changeset de79d9893d50 in trytond:5.6
details: https://hg.tryton.org/trytond?cmd=changeset;node=de79d9893d50
description:
        Delete read data after having instantiated all targets

        Some read value may be needed to instantiate other records if it is 
used in the
        context.
        Also the test to fill fields dictionary was always false as it tested 
the field
        instance instead of the name.

        issue9380
        review298171002
        (grafted from 242491ac0135a2c4d4f186313a5b88aaa2966277)
diffstat:

 trytond/model/modelstorage.py |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r 340f068d78c0 -r de79d9893d50 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py     Thu Jul 16 19:02:48 2020 +0200
+++ b/trytond/model/modelstorage.py     Mon Jul 13 20:55:53 2020 +0200
@@ -1459,9 +1459,10 @@
         # add datetime_field
         for field in list(ffields.values()):
             if hasattr(field, 'datetime_field') and field.datetime_field:
-                datetime_field = self._fields[field.datetime_field]
-                ffields[field.datetime_field] = datetime_field
                 require_context_field = True
+                if field.datetime_field not in ffields:
+                    datetime_field = self._fields[field.datetime_field]
+                    ffields[field.datetime_field] = datetime_field
 
         # add depends of field with context
         for field in list(ffields.values()):
@@ -1470,9 +1471,9 @@
                 for context_field_name in eval_fields:
                     if context_field_name not in field.depends:
                         continue
-                    context_field = self._fields.get(context_field_name)
                     require_context_field = True
-                    if context_field not in ffields:
+                    if context_field_name not in ffields:
+                        context_field = self._fields.get(context_field_name)
                         ffields[context_field_name] = context_field
 
         def filter_(id_):
@@ -1560,6 +1561,7 @@
                 read_data = self.read(list(ids), list(ffields.keys()))
             # create browse records for 'remote' models
             for data in read_data:
+                to_delete = set()
                 for fname, field in ffields.items():
                     fvalue = data[fname]
                     if field._type in ('many2one', 'one2one', 'one2many',
@@ -1578,10 +1580,11 @@
                             or field.context
                             or getattr(field, 'datetime_field', None)
                             or isinstance(field, fields.Function)):
-                        del data[fname]
+                        to_delete.add(fname)
                 if data['id'] not in self._cache:
                     self._cache[data['id']] = {}
-                self._cache[data['id']].update(data)
+                self._cache[data['id']].update(
+                    **{k: v for k, v in data.items() if k not in to_delete})
         return value
 
     @property

Reply via email to