Do not copy Binary content with file_id

This avoid the filestore to reprocess the binary data as the file_id is
already copied.

issue9153
review297241002
This commit is contained in:
Cédric Krier
2020-03-28 16:57:05 +01:00
parent 7691b89822
commit 72a71019c0
4 changed files with 40 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Do not copy Binary content with file_id
* Replace memoize with functools.lru_cache
* Add support for Python 3.8
* Set all fields readonly for inactive record
+4
View File
@@ -383,6 +383,10 @@ class ModelStorage(Model):
del data[field_name]
elif data[field_name]:
data[field_name] = [('add', data[field_name])]
elif ftype == 'binary':
# Copy only file_id
if field.file_id and origin.get(field.file_id):
del data[field_name]
if 'id' in data:
del data['id']
return data
+9
View File
@@ -93,6 +93,14 @@ class CopyMany2ManyReferenceRelation(ModelSQL):
'Many2ManyReference Target')
class CopyBinary(ModelSQL):
"Copy Binary"
__name__ = 'test.copy.binary'
binary = fields.Binary("Binary")
binary_id = fields.Binary("Binary with ID", file_id='file_id')
file_id = fields.Char("Binary ID")
def register(module):
Pool.register(
Copy,
@@ -106,4 +114,5 @@ def register(module):
CopyMany2ManyReference,
CopyMany2ManyReferenceTarget,
CopyMany2ManyReferenceRelation,
CopyBinary,
module=module, type_='model')
+26
View File
@@ -3,6 +3,7 @@
# this repository contains the full copyright notices and license terms.
import unittest
from trytond.model import fields
from trytond.tests.test_tryton import activate_module, with_transaction
from trytond.pool import Pool
@@ -169,6 +170,31 @@ class CopyTestCase(unittest.TestCase):
self.assertSequenceEqual(record_copy.many2many, [target])
@with_transaction()
def test_binary(self):
"Test copy binary"
pool = Pool()
Binary = pool.get('test.copy.binary')
record = Binary(binary=fields.Binary.cast(b'data'))
record.save()
record_copy, = Binary.copy([record])
self.assertEqual(record_copy.binary, record.binary)
@with_transaction()
def test_binary_file_id(self):
"Test copy binary with file_id"
pool = Pool()
Binary = pool.get('test.copy.binary')
record = Binary(binary_id=fields.Binary.cast(b'data'))
record.save()
record_copy, = Binary.copy([record])
self.assertEqual(record_copy.file_id, record.file_id)
self.assertEqual(record_copy.binary_id, record.binary_id)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(CopyTestCase)