[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:
Raphael Collet
2015-03-26 18:44:51 +01:00
committed by Christophe Simonis
parent 313acf87a2
commit 58d6bb30ab
2 changed files with 8 additions and 9 deletions
+3 -4
View File
@@ -37,10 +37,9 @@ class ir_http(orm.AbstractModel):
def _auth_method_public(self):
if not request.session.uid:
domain_name = request.httprequest.environ.get('HTTP_HOST', '').split(':')[0]
website_id = self.pool['website']._get_current_website_id(request.cr, openerp.SUPERUSER_ID, domain_name, context=request.context)
if website_id:
request.uid = self.pool['website'].browse(request.cr, openerp.SUPERUSER_ID, website_id, request.context).user_id.id
website = self.pool['website'].get_current_website(request.cr, openerp.SUPERUSER_ID, context=request.context)
if website:
request.uid = website.user_id.id
else:
request.uid = self.pool['ir.model.data'].xmlid_to_res_id(request.cr, openerp.SUPERUSER_ID, 'base', 'public_user')
else:
+5 -5
View File
@@ -350,17 +350,17 @@ class website(osv.osv):
lang['hreflang'] = lang['short']
return langs
@openerp.tools.ormcache(skiparg=4)
def _get_current_website_id(self, cr, uid, domain_name, context=None):
ids = self.search(cr, uid, [('name', '=', domain_name)], limit=1, context=context)
@openerp.tools.ormcache(skiparg=3)
def _get_current_website_id(self, cr, uid, domain_name):
ids = self.search(cr, uid, [('name', '=', domain_name)], limit=1)
if ids:
return ids[0]
else:
return self.search(cr, uid, [], limit=1, context=context)[0]
return self.search(cr, uid, [], limit=1)[0]
def get_current_website(self, cr, uid, context=None):
domain_name = request.httprequest.environ.get('HTTP_HOST', '').split(':')[0]
website_id = self._get_current_website_id(cr, uid, domain_name, context=context)
website_id = self._get_current_website_id(cr, uid, domain_name)
request.context['website_id'] = website_id
return self.browse(cr, uid, website_id, context=context)