Skip to content

Don't try to rollback a closed transaction #531

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions neo4j/work/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
sleep,
)

from neo4j.conf import SessionConfig
from neo4j.api import (
READ_ACCESS,
WRITE_ACCESS,
)
from neo4j.conf import SessionConfig
from neo4j.data import DataHydrator
from neo4j.exceptions import (
ClientError,
Expand Down Expand Up @@ -337,7 +337,7 @@ def _run_transaction(self, access_mode, transaction_function, *args, **kwargs):
try:
result = transaction_function(tx, *args, **kwargs)
except Exception:
tx.rollback()
tx.close()
raise
else:
tx.commit()
Expand Down
21 changes: 11 additions & 10 deletions neo4j/work/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def commit(self):
if self._closed:
raise TransactionError("Transaction closed")
metadata = {}
self._consume_results() # DISCARD pending records then do a commit.
try:
self._consume_results() # DISCARD pending records then do a commit.
self._connection.commit(on_success=metadata.update)
self._connection.send_all()
self._connection.fetch_all()
Expand All @@ -159,18 +159,19 @@ def rollback(self):
if self._closed:
raise TransactionError("Transaction closed")
metadata = {}
if not self._connection._is_reset:
self._consume_results() # DISCARD pending records then do a rollback.
self._connection.rollback(on_success=metadata.update)
self._connection.send_all()
self._connection.fetch_all()
self._closed = True
self._on_closed()
try:
if not self._connection._is_reset:
# DISCARD pending records then do a rollback.
self._consume_results()
self._connection.rollback(on_success=metadata.update)
self._connection.send_all()
self._connection.fetch_all()
finally:
self._closed = True
self._on_closed()

def close(self):
"""Close this transaction, triggering a ROLLBACK if not closed.

:raise TransactionError: if the transaction could not perform a ROLLBACK.
"""
if self._closed:
return
Expand Down