[MERGE] manual forward port of changes made in http dispatching in saas-2 branch...
authorChristophe Simonis <chs@openerp.com>
Mon, 25 Nov 2013 16:58:04 +0000 (17:58 +0100)
committerChristophe Simonis <chs@openerp.com>
Mon, 25 Nov 2013 16:58:04 +0000 (17:58 +0100)
bzr revid: chs@openerp.com-20131125165804-0d25q1vn5z0y9nv8

openerp/addons/base/ir/ir_http.py
openerp/http.py

index 56c0074..ff8a2a8 100644 (file)
@@ -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
 
index e22cf04..993af6d 100644 (file)
@@ -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: