From 58d6bb30ab9dd101285def6db20b9db5df300240 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 26 Mar 2015 14:55:03 +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/ir_http.py | 7 +++---- addons/website/models/website.py | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index b109bdbecd8..7726c4c8cf7 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -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: diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 2784b55fef4..2c1a373d586 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -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)