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
This commit is contained in:
1 parent
26b87dd919
commit
d882e84c74
1 file changed
+9
-6
@@ -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
|
||||
|
||||
Reference in new issue
Block a user