[FIX] core: _create() should not set non-stored field to None in cache
When _create() is invoked, it inserts rows into the database, and sets the cache of the corresponding records to the values that are inserted. If a field is not passed to _create(), we assume that its database value will be NULL (or falsy, at least) and put None in cache, in order to avoid fetching that value. However, this only makes sense for stored fields. Part-of: odoo/odoo#133021
This commit is contained in:
committed by
Jorge Pinna Puissant
parent
a8e4838a6a
commit
b28265dbb2
@@ -1831,7 +1831,6 @@ class TestFields(TransactionCaseWithUserDemo):
|
||||
""" test field access on new records vs real records. """
|
||||
Model = self.env['test_new_api.category']
|
||||
real_record = Model.create({'name': 'Foo'})
|
||||
self.env.invalidate_all()
|
||||
new_origin = Model.new({'name': 'Bar'}, origin=real_record)
|
||||
new_record = Model.new({'name': 'Baz'})
|
||||
|
||||
|
||||
+1
-1
@@ -4459,7 +4459,7 @@ class BaseModel(metaclass=MetaModel):
|
||||
# in other words, if `parent_id` is not set, no other message `child_ids` are impacted.
|
||||
# + avoid the fetch of fields which are False. e.g. if a boolean field is not passed in vals and as no default set in the field attributes,
|
||||
# then we know it can be set to False in the cache in the case of a create.
|
||||
elif field.name not in set_vals and not field.compute:
|
||||
elif field.store and field.name not in set_vals and not field.compute:
|
||||
self.env.cache.set(record, field, field.convert_to_cache(None, record))
|
||||
for fname, value in vals.items():
|
||||
field = self._fields[fname]
|
||||
|
||||
Reference in New Issue
Block a user