Fix transaction corruption in case of rollback failure
@@ -161,10 +161,15 @@ class Database(local, NodeClassRegistry):
:return: last_bookmark
"""
+ try:
self._active_transaction.commit()
last_bookmark = self._session.last_bookmark()
+ finally:
+ # In case when something went wrong during committing changes to the database, we have to close
+ # an active transaction and session.
self._active_transaction = None
self._session = None
+
return last_bookmark
@ensure_connection
@@ -172,7 +177,11 @@ class Database(local, NodeClassRegistry):
"""
Rolls back the current transaction
"""
+ try:
self._active_transaction.rollback()
+ finally:
+ # In case when something went wrong during changes rollback, we have to close an active transaction and
+ # session
self._active_transaction = None
self._session = None
@@ -319,13 +328,7 @@ class TransactionProxy(object):
raise UniqueProperty(exc_value.message)
if not exc_value:
- try:
self.last_bookmark = self.db.commit()
- except:
- # In case when something went wrong during committing changes to the database, we have to close
- # an active transaction.
- self.db._active_transaction = None
- raise
def __call__(self, func):
def wrapper(*args, **kwargs):
