Do not copy binary field with file_id only if copied data is not changed
This commit is contained in:
1 parent
c5a3340851
commit
455d8c362b
2 files changed
+51
-1
No files matched your search
@@ -431,7 +431,9 @@ class ModelStorage(Model):
|
||||
data[field_name] = [('add', data[field_name])]
|
||||
elif ftype == 'binary':
|
||||
# Copy only file_id
|
||||
if field.file_id and origin.get(field.file_id):
|
||||
if (field.file_id
|
||||
and origin.get(field.file_id)
|
||||
and data[field_name] == origin.get(field_name)):
|
||||
del data[field_name]
|
||||
if 'id' in data:
|
||||
del data['id']
|
||||
|
||||
@@ -202,3 +202,51 @@ class FieldBinaryTestCase(unittest.TestCase):
|
||||
|
||||
self.assertEqual(binary.binary, None)
|
||||
self.assertEqual(binary.binary_id, None)
|
||||
|
||||
@with_transaction()
|
||||
def test_copy(self):
|
||||
"Test copy binary"
|
||||
pool = Pool()
|
||||
Binary = pool.get('test.binary')
|
||||
binary = Binary(binary=b'foo')
|
||||
binary.save()
|
||||
|
||||
copy, = Binary.copy([binary])
|
||||
|
||||
self.assertEqual(binary.binary, copy.binary)
|
||||
|
||||
@with_transaction()
|
||||
def test_copy_with_default(self):
|
||||
"Test copy binary with default"
|
||||
pool = Pool()
|
||||
Binary = pool.get('test.binary')
|
||||
binary = Binary(binary=b'foo')
|
||||
binary.save()
|
||||
|
||||
copy, = Binary.copy([binary], default={'binary': b'bar'})
|
||||
|
||||
self.assertEqual(copy.binary, b'bar')
|
||||
|
||||
@with_transaction()
|
||||
def test_copy_with_filestorage(self):
|
||||
"Test copy binary with filestorage"
|
||||
pool = Pool()
|
||||
Binary = pool.get('test.binary_filestorage')
|
||||
binary = Binary(binary=b'foo')
|
||||
binary.save()
|
||||
|
||||
copy, = Binary.copy([binary])
|
||||
|
||||
self.assertEqual(binary.binary, copy.binary)
|
||||
|
||||
@with_transaction()
|
||||
def test_copy_with_filestorage_default(self):
|
||||
"Test copy binary with filestorage and default"
|
||||
pool = Pool()
|
||||
Binary = pool.get('test.binary_filestorage')
|
||||
binary = Binary(binary=b'foo')
|
||||
binary.save()
|
||||
|
||||
copy, = Binary.copy([binary], default={'binary': b'bar'})
|
||||
|
||||
self.assertEqual(copy.binary, b'bar')
|
||||
Reference in new issue
Block a user