changeset 64260c389ec1 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=64260c389ec1
description:
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
diffstat:
CHANGELOG | 1 +
trytond/model/modelstorage.py | 4 ++++
trytond/tests/copy_.py | 9 +++++++++
trytond/tests/test_copy.py | 26 ++++++++++++++++++++++++++
4 files changed, 40 insertions(+), 0 deletions(-)
diffs (89 lines):
diff -r c9feb4395bf0 -r 64260c389ec1 CHANGELOG
--- a/CHANGELOG Sat Mar 28 00:33:27 2020 +0100
+++ b/CHANGELOG Sat Mar 28 16:57:05 2020 +0100
@@ -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
diff -r c9feb4395bf0 -r 64260c389ec1 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py Sat Mar 28 00:33:27 2020 +0100
+++ b/trytond/model/modelstorage.py Sat Mar 28 16:57:05 2020 +0100
@@ -383,6 +383,10 @@
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
diff -r c9feb4395bf0 -r 64260c389ec1 trytond/tests/copy_.py
--- a/trytond/tests/copy_.py Sat Mar 28 00:33:27 2020 +0100
+++ b/trytond/tests/copy_.py Sat Mar 28 16:57:05 2020 +0100
@@ -93,6 +93,14 @@
'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 @@
CopyMany2ManyReference,
CopyMany2ManyReferenceTarget,
CopyMany2ManyReferenceRelation,
+ CopyBinary,
module=module, type_='model')
diff -r c9feb4395bf0 -r 64260c389ec1 trytond/tests/test_copy.py
--- a/trytond/tests/test_copy.py Sat Mar 28 00:33:27 2020 +0100
+++ b/trytond/tests/test_copy.py Sat Mar 28 16:57:05 2020 +0100
@@ -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 @@
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)