From 5528b9b2d89c5f6a95b9d1a8f67cbe83c1643bed Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 23 Jan 2014 12:54:13 +0100 Subject: [PATCH] [FIX] sprurious error in log during javascript unit tests During some tests, the runner performs sequences of DUPLICATE and DROP on databases. Each DUPLICATE is followed by some operations then a DROP. Problem is, after a DROP the next DUPLICATE RPC query will attempt a connection to the just-dropped database, openerp.sql_db will log an OperationalError ("Connection to the database failed" since the db it tries to connect to was removed) then the HTTP dispatcher will just switch to "nodb" and continue on its merry way. Mute the sql_db logger while attempting to fetch the ir.http object. Also assert that the logger name is a string in mute_logger, as `mute_logger(openerp.sql_db)` is syntactically valid, but will not do anything. bzr revid: xmo@openerp.com-20140123115413-ax5patcomdfp3ue3 --- openerp/http.py | 9 ++++++--- openerp/tools/misc.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/openerp/http.py b/openerp/http.py index f3431584807..d9846b64e3b 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -35,6 +35,7 @@ import werkzeug.wsgi import openerp from openerp.service import security, model as service_model +import openerp.tools _logger = logging.getLogger(__name__) @@ -1027,10 +1028,12 @@ class Root(object): if db: openerp.modules.registry.RegistryManager.check_registry_signaling(db) try: - ir_http = request.registry['ir.http'] + with openerp.tools.mute_logger('openerp.sql_db'): + 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 + # psycopg2 error. At this point, that means the + # database probably does not exists anymore. Log the + # user out and fall back to nodb request.session.logout() result = _dispatch_nodb() else: diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 1557d2d2276..251905137c0 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -1075,6 +1075,8 @@ class mute_logger(object): def __enter__(self): for logger in self.loggers: + assert isinstance(logger, basestring),\ + "A logger name must be a string, got %s" % type(logger) logging.getLogger(logger).addFilter(self) def __exit__(self, exc_type=None, exc_val=None, exc_tb=None):