From 0beb14f0d23c9cfecb4aeb329869716bee8f8c8a Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 26 Mar 2015 14:38:32 +0100 Subject: [PATCH] [FIX] ormcache: fix calls to `ormcache` with unexpected context parameter The implementation of `ormcache` does not work on methods that take a `context` parameter. Because of the decorator `decorator`, the arguments of the call are passed positionally to the method `ormcache.lookup`, and positional arguments are used in the cache key. The fix consists in removing the `context` parameter from the faulty methods, either directly, or by caching a private method called by the public method. --- addons/website/models/website.py | 4 ++-- openerp/addons/base/ir/ir_attachment.py | 2 +- openerp/addons/base/ir/ir_model.py | 7 +++++-- openerp/addons/base/res/res_users.py | 9 ++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 006e6c4a10f..826a77022da 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -228,12 +228,12 @@ class website(osv.osv): return False @openerp.tools.ormcache(skiparg=3) - def _get_languages(self, cr, uid, id, context=None): + def _get_languages(self, cr, uid, id): website = self.browse(cr, uid, id) return [(lg.code, lg.name) for lg in website.language_ids] def get_languages(self, cr, uid, ids, context=None): - return self._get_languages(cr, uid, ids[0], context=context) + return self._get_languages(cr, uid, ids[0]) def get_alternate_languages(self, cr, uid, ids, req=None, context=None): langs = [] diff --git a/openerp/addons/base/ir/ir_attachment.py b/openerp/addons/base/ir/ir_attachment.py index 77e4190f552..e3cd3aa6db3 100644 --- a/openerp/addons/base/ir/ir_attachment.py +++ b/openerp/addons/base/ir/ir_attachment.py @@ -72,7 +72,7 @@ class ir_attachment(osv.osv): return self.pool['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'ir_attachment.location', 'file') @tools.ormcache(skiparg=3) - def _filestore(self, cr, uid, context=None): + def _filestore(self, cr, uid): return tools.config.filestore(cr.dbname) def force_storage(self, cr, uid, context=None): diff --git a/openerp/addons/base/ir/ir_model.py b/openerp/addons/base/ir/ir_model.py index e488515b09a..98baa1255fe 100644 --- a/openerp/addons/base/ir/ir_model.py +++ b/openerp/addons/base/ir/ir_model.py @@ -732,7 +732,7 @@ class ir_model_access(osv.osv): return [('%s/%s' % x) if x[0] else x[1] for x in cr.fetchall()] @tools.ormcache() - def check(self, cr, uid, model, mode='read', raise_exception=True, context=None): + def _check(self, cr, uid, model, mode='read', raise_exception=True): if uid==1: # User root have all accesses # TODO: exclude xml-rpc requests @@ -796,6 +796,9 @@ class ir_model_access(osv.osv): raise openerp.exceptions.AccessError(msg % msg_params) return bool(r) + def check(self, cr, uid, model, mode='read', raise_exception=True, context=None): + return self._check(cr, uid, model, mode, raise_exception) + __cache_clearing_methods = [] def register_cache_clearing_method(self, model, method): @@ -810,7 +813,7 @@ class ir_model_access(osv.osv): def call_cache_clearing_methods(self, cr): self.invalidate_cache(cr, SUPERUSER_ID) - self.check.clear_cache(self) # clear the cache of check function + self._check.clear_cache(self) # clear the cache of check function for model, method in self.__cache_clearing_methods: if model in self.pool: getattr(self.pool[model], method)() diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 6ef7e0b4792..0ce5b6fa242 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -338,7 +338,7 @@ class res_users(osv.osv): for id in ids: if id in self._uid_cache[db]: del self._uid_cache[db][id] - self.context_get.clear_cache(self) + self._context_get.clear_cache(self) self.has_group.clear_cache(self) return res @@ -374,8 +374,8 @@ class res_users(osv.osv): return super(res_users, self).copy(cr, uid, id, default, context) @tools.ormcache(skiparg=2) - def context_get(self, cr, uid, context=None): - user = self.browse(cr, SUPERUSER_ID, uid, context) + def _context_get(self, cr, uid): + user = self.browse(cr, SUPERUSER_ID, uid) result = {} for k in self._fields: if k.startswith('context_'): @@ -391,6 +391,9 @@ class res_users(osv.osv): result[context_key] = res or False return result + def context_get(self, cr, uid, context=None): + return self._context_get(cr, uid) + def action_get(self, cr, uid, context=None): dataobj = self.pool['ir.model.data'] data_id = dataobj._get_id(cr, SUPERUSER_ID, 'base', 'action_res_users_my')