From b28265dbb29acf629ebcf8283832ac2867959745 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 31 Aug 2023 09:19:43 +0200 Subject: [PATCH] [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 --- odoo/addons/test_new_api/tests/test_new_fields.py | 1 - odoo/models.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index 294a3edf0e1..fd4207467a8 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -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'}) diff --git a/odoo/models.py b/odoo/models.py index e5d8d3208a7..2dfb8a9dfc5 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -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]