From d882e84c7443d04cda677ddab93e7def4cbccc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 13 Jul 2020 20:55:53 +0200 Subject: [PATCH] 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 --- trytond/model/modelstorage.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 40f7d28f75..7f0f72aa93 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -1464,9 +1464,10 @@ class ModelStorage(Model): # 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()): @@ -1475,9 +1476,9 @@ class ModelStorage(Model): 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_): @@ -1569,6 +1570,7 @@ class ModelStorage(Model): # create browse records for 'remote' models for data in read_data: id_ = data['id'] + to_delete = set() for fname, field in ffields.items(): fvalue = data[fname] if field._type in { @@ -1583,8 +1585,9 @@ class ModelStorage(Model): or field.context or getattr(field, 'datetime_field', None) or isinstance(field, fields.Function)): - del data[fname] - self._cache[id_]._update(data) + to_delete.add(fname) + self._cache[id_]._update( + **{k: v for k, v in data.items() if k not in to_delete}) return value @property