summaryrefslogtreecommitdiff
path: root/odoo/sql_db.py
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/sql_db.py')
-rw-r--r--odoo/sql_db.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/odoo/sql_db.py b/odoo/sql_db.py
index 1c15f4e4a2d..c5af069728e 100644
--- a/odoo/sql_db.py
+++ b/odoo/sql_db.py
@@ -107,6 +107,8 @@ class BaseCursor:
def __init__(self):
self.precommit = tools.Callbacks()
self.postcommit = tools.Callbacks()
+ self.prerollback = tools.Callbacks()
+ self.postrollback = tools.Callbacks()
@contextmanager
@check
@@ -378,10 +380,11 @@ class Cursor(BaseCursor):
# collected as fast as they should). The problem is probably due in
# part because browse records keep a reference to the cursor.
del self._obj
- self._closed = True
- # Clean the underlying connection.
- self._cnx.rollback()
+ # Clean the underlying connection, and run rollback hooks.
+ self.rollback()
+
+ self._closed = True
if leak:
self._cnx.leaked = True
@@ -433,7 +436,7 @@ class Cursor(BaseCursor):
if event == 'commit':
self.postcommit.add(func)
elif event == 'rollback':
- raise NotImplementedError()
+ self.postrollback.add(func)
@check
def commit(self):
@@ -441,6 +444,8 @@ class Cursor(BaseCursor):
flush_env(self)
self.precommit.run()
result = self._cnx.commit()
+ self.prerollback.clear()
+ self.postrollback.clear()
self.postcommit.run()
return result
@@ -450,7 +455,9 @@ class Cursor(BaseCursor):
clear_env(self)
self.precommit.clear()
self.postcommit.clear()
+ self.prerollback.run()
result = self._cnx.rollback()
+ self.postrollback.run()
return result
@check
@@ -496,8 +503,8 @@ class TestCursor(BaseCursor):
def close(self):
if not self._closed:
+ self.rollback()
self._closed = True
- self._cursor.execute('ROLLBACK TO SAVEPOINT "%s"' % self._savepoint)
self._lock.release()
def autocommit(self, on):
@@ -509,16 +516,19 @@ class TestCursor(BaseCursor):
flush_env(self)
self.precommit.run()
self._cursor.execute('SAVEPOINT "%s"' % self._savepoint)
- # ignore post-commit hooks
- self.postcommit.clear()
+ self.prerollback.clear()
+ self.postrollback.clear()
+ self.postcommit.clear() # TestCursor ignores post-commit hooks
@check
def rollback(self):
""" Perform an SQL `ROLLBACK` """
clear_env(self)
self.precommit.clear()
- self._cursor.execute('ROLLBACK TO SAVEPOINT "%s"' % self._savepoint)
self.postcommit.clear()
+ self.prerollback.run()
+ self._cursor.execute('ROLLBACK TO SAVEPOINT "%s"' % self._savepoint)
+ self.postrollback.run()
def __getattr__(self, name):
value = getattr(self._cursor, name)