From 266f99f54568e018137860cacedab65d03ff6866 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 1 Feb 2019 10:07:45 +0000 Subject: [FIX] tools: use of savepoints in TestCursor closes odoo/odoo#30768 --- odoo/sql_db.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'odoo/sql_db.py') diff --git a/odoo/sql_db.py b/odoo/sql_db.py index 873cbac3042..a46b6860dc5 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -432,16 +432,18 @@ class TestCursor(Cursor): """ def __init__(self, *args, **kwargs): super(TestCursor, self).__init__(*args, **kwargs) - # in order to simulate commit and rollback, the cursor maintains a - # savepoint at its last commit - self.execute("SAVEPOINT test_cursor") # we use a lock to serialize concurrent requests self._lock = threading.RLock() def acquire(self): self._lock.acquire() + # the cursor maintains a savepoint at its last commit point + self.execute("SAVEPOINT test_cursor") def release(self): + # the cursor should be right after the savepoint; release it to make + # former savepoints directly accessible + self.execute("RELEASE SAVEPOINT test_cursor") self._lock.release() def force_close(self): @@ -456,12 +458,13 @@ class TestCursor(Cursor): _logger.debug("TestCursor.autocommit(%r) does nothing", on) def commit(self): + # move the savepoint to the current position self.execute("RELEASE SAVEPOINT test_cursor") self.execute("SAVEPOINT test_cursor") def rollback(self): + # this does not release the savepoint; release() will do it self.execute("ROLLBACK TO SAVEPOINT test_cursor") - self.execute("SAVEPOINT test_cursor") class LazyCursor(object): """ A proxy object to a cursor. The cursor itself is allocated only if it is -- cgit v1.2.3