[IMP] make TestCursor more robust, and remove some tests on tools.config['test_enable']
authorRaphael Collet <rco@openerp.com>
Wed, 9 Apr 2014 10:33:37 +0000 (12:33 +0200)
committerRaphael Collet <rco@openerp.com>
Wed, 9 Apr 2014 10:33:37 +0000 (12:33 +0200)
bzr revid: rco@openerp.com-20140409103337-r0a1nx9h8nfg3cn3

openerp/addons/base/res/res_users.py
openerp/http.py
openerp/sql_db.py

index 9ce0efd..32e81ee 100644 (file)
@@ -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:
index 370d8ca..24a1f77 100644 (file)
@@ -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)
 
index c93f4fb..126460f 100644 (file)
@@ -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")