From 28581cc73442747463386b1a84d1c54d15128078 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 25 Nov 2013 17:58:04 +0100 Subject: [PATCH] [MERGE] manual forward port of changes made in http dispatching in saas-2 branch since last web revid 3865 dle@openerp.com-20131023113414-mlwppd4d7vyh1tyj bzr revid: chs@openerp.com-20131125165804-0d25q1vn5z0y9nv8 --- openerp/addons/base/ir/ir_http.py | 4 +--- openerp/http.py | 37 ++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/openerp/addons/base/ir/ir_http.py b/openerp/addons/base/ir/ir_http.py index 56c00743900..ff8a2a8ebd8 100644 --- a/openerp/addons/base/ir/ir_http.py +++ b/openerp/addons/base/ir/ir_http.py @@ -52,7 +52,6 @@ class ModelsConverter(werkzeug.routing.BaseConverter): class ir_http(osv.AbstractModel): _name = 'ir.http' - _description = "HTTP routing" def _get_converters(self): @@ -83,9 +82,8 @@ class ir_http(osv.AbstractModel): # what if error in security.check() # -> res_users.check() # -> res_users.check_credentials() - except http.SessionExpiredException: + except Exception: request.session.logout() - raise http.SessionExpiredException("Session expired for request %s" % request.httprequest) getattr(self, "_auth_method_%s" % auth_method)() return auth_method diff --git a/openerp/http.py b/openerp/http.py index e22cf04b04d..993af6d2752 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -24,6 +24,7 @@ import urlparse import warnings import babel.core +import psycopg2 import simplejson import werkzeug.contrib.sessions import werkzeug.datastructures @@ -920,11 +921,9 @@ class Root(object): return explicit_session def setup_db(self, httprequest): - # if no db is found on the session try to deduce it from the domain - db = db_monodb(httprequest) - if db != httprequest.session.db: - httprequest.session.logout() - httprequest.session.db = db + if not httprequest.session.db: + # allow "admin" routes to works without being logged in when in monodb. + httprequest.session.db = db_monodb(httprequest) def setup_lang(self, httprequest): if not "lang" in httprequest.session.context: @@ -975,18 +974,30 @@ class Root(object): request = self.get_request(httprequest) + def _dispatch_nodb(): + func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match() + request.set_handler(func, arguments, "none") + result = request.dispatch() + return result + with set_request(request): - db = request.session.db + db = request.session.db if db: openerp.modules.registry.RegistryManager.check_registry_signaling(db) - result = request.registry['ir.http']._dispatch() - openerp.modules.registry.RegistryManager.signal_caches_change(db) + try: + ir_http = request.registry['ir.http'] + except psycopg2.OperationalError: + # psycopg2 error. At this point, that's mean the database does not exists + # anymore. We unlog the user and failback in nodb mode + request.session.logout() + result = _dispatch_nodb() + else: + result = ir_http._dispatch() + openerp.modules.registry.RegistryManager.signal_caches_change(db) else: - # fallback to non-db handlers - func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match() - request.set_handler(func, arguments, "none") - result = request.dispatch() - response = self.get_response(httprequest, result, explicit_session) + result = _dispatch_nodb() + + response = self.get_response(httprequest, result, explicit_session) return response(environ, start_response) except werkzeug.exceptions.HTTPException, e: