[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.
This commit is contained in:
parent
3eda25119f
commit
0beb14f0d2
|
@ -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 = []
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)()
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue