From 331d8451d9011aff6a8290c473a52fa77b30b358 Mon Sep 17 00:00:00 2001 From: "Benjamin Hanquin (beha)" Date: Tue, 27 Feb 2024 12:42:37 +0100 Subject: [PATCH] [FIX] base, website: Avoid .cache confusion with Environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The attribute cache is mainly used from the Environment class. The ormcache attribute using the same name leads to confusion. Related task: task-3818968 closes odoo/odoo#155264 Signed-off-by: Rémy Voet (ryv) --- addons/website/models/ir_http.py | 2 +- odoo/addons/base/models/ir_model.py | 2 +- odoo/tools/cache.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index ea8994346a6..e59be192097 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -90,7 +90,7 @@ class Http(models.AbstractModel): website_id = request.website_routing logger.debug("_generate_routing_rules for website: %s", website_id) rewrites = self._get_rewrites(website_id) - self._rewrite_len.cache.add_value(self, website_id, cache_value=len(rewrites)) + self._rewrite_len.__cache__.add_value(self, website_id, cache_value=len(rewrites)) for url, endpoint in super()._generate_routing_rules(modules, converters): if url in rewrites: diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index fc2d4a23bc5..e01202bff08 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -2279,7 +2279,7 @@ class IrModelData(models.Model): for module, name, model, res_id, create_date, write_date in result: # small optimisation: during install a lot of xmlid are created/updated. # Instead of clearing the cache, set the correct value in the cache to avoid a bunch of query - self._xmlid_lookup.cache.add_value(self, f"{module}.{name}", cache_value=(model, res_id)) + self._xmlid_lookup.__cache__.add_value(self, f"{module}.{name}", cache_value=(model, res_id)) if create_date != write_date: # something was updated, notify other workers # it is possible that create_date and write_date diff --git a/odoo/tools/cache.py b/odoo/tools/cache.py index 217e0beb857..9cb568356b5 100644 --- a/odoo/tools/cache.py +++ b/odoo/tools/cache.py @@ -59,7 +59,7 @@ class ormcache(object): self.method = method self.determine_key() lookup = decorator(self.lookup, method) - lookup.cache = self + lookup.__cache__ = self return lookup def add_value(self, *args, cache_value=None, **kwargs): @@ -173,7 +173,7 @@ def log_ormcache_stats(sig=None, frame=None): def get_cache_key_counter(bound_method, *args, **kwargs): """ Return the cache, key and stat counter for the given call. """ model = bound_method.__self__ - ormcache = bound_method.cache + ormcache = bound_method.__cache__ cache, key0, counter = ormcache.lru(model) key = key0 + ormcache.key(model, *args, **kwargs) return cache, key, counter