From fd8fd0906f3ecb79c9316d4dffbc6ae0b6377de7 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 9 Apr 2014 12:33:37 +0200 Subject: [PATCH] [IMP] make TestCursor more robust, and remove some tests on tools.config['test_enable'] bzr revid: rco@openerp.com-20140409103337-r0a1nx9h8nfg3cn3 --- openerp/addons/base/res/res_users.py | 3 +-- openerp/http.py | 2 +- openerp/sql_db.py | 9 +++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 9ce0efd2eb8..32e81ee600f 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -394,8 +394,7 @@ class res_users(osv.osv): # (In this way, there is no opportunity to have two transactions # interleaving their cr.execute()..cr.commit() calls and have one # of them rolled back due to a concurrent access.) - if not openerp.tools.config['test_enable']: - cr.autocommit(True) + cr.autocommit(True) # check if user exists res = self.search(cr, SUPERUSER_ID, [('login','=',login)]) if res: diff --git a/openerp/http.py b/openerp/http.py index 370d8ca7f30..24a1f77afe5 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -279,7 +279,7 @@ class WebRequest(object): def checked_call(___dbname, *a, **kw): # The decorator can call us more than once if there is an database error. In this # case, the request cursor is unusable. Rollback transaction to create a new one. - if self._cr and not openerp.tools.config['test_enable']: + if self._cr: self._cr.rollback() return self.endpoint(*a, **kw) diff --git a/openerp/sql_db.py b/openerp/sql_db.py index c93f4fbb92f..126460f5317 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -391,7 +391,6 @@ class TestCursor(Cursor): super(TestCursor, self).__init__(*args, **kwargs) super(TestCursor, self).execute("SAVEPOINT test_cursor") self._lock = threading.RLock() - self._auto_commit = False def acquire(self): self._lock.acquire() @@ -401,18 +400,16 @@ class TestCursor(Cursor): def execute(self, *args, **kwargs): super(TestCursor, self).execute(*args, **kwargs) - if self._auto_commit: - self.commit() def close(self, force=False): - self.rollback() # for stuff that has not been committed if force: super(TestCursor, self).close() - else: + elif not self._closed: + self.rollback() # for stuff that has not been committed self.release() def autocommit(self, on): - self._auto_commit = on + _logger.debug("TestCursor.autocommit(%r) does nothing", on) def commit(self): super(TestCursor, self).execute("RELEASE SAVEPOINT test_cursor")