Skip to content

Commit ea8d1fa

Browse files
authored
TransactionError on session.run() on busy session (#1170)
Raise `TransactionError` (subclass of `DriverError`) instead of `ClientError` (subclass of `Neo4jError`) when calling `session.run()` while an explicit transaction is active on that session. - This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side errors. - It is now the same error raised as when trying to start an explicit transaction while another explicit transaction is already active.
1 parent 7b07121 commit ea8d1fa

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
4040
- `connection_acquisition_timeout` configuration option
4141
- `ValueError` on invalid values (instead of `ClientError`)
4242
- Consistently restrict the value to be strictly positive
43+
- `TransactionError` (subclass of `DriverError`) instead of `ClientError` (subclass of `Neo4jError`) when calling
44+
`session.run()` while an explicit transaction is active on that session.
45+
- This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side
46+
errors.
47+
- It is now the same error raised as when trying to start an explicit transaction while another explicit transaction
48+
is already active.
4349

4450

4551
## Version 5.28

src/neo4j/_async/work/session.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
WRITE_ACCESS,
4242
)
4343
from ...exceptions import (
44-
ClientError,
4544
DriverError,
4645
Neo4jError,
4746
ServiceUnavailable,
@@ -293,6 +292,7 @@ async def run(
293292
294293
:returns: a new :class:`neo4j.AsyncResult` object
295294
295+
:raises TransactionError: if a transaction is already open.
296296
:raises SessionError: if the session has been closed.
297297
"""
298298
self._check_state()
@@ -302,9 +302,8 @@ async def run(
302302
raise TypeError("query must be a string or a Query instance")
303303

304304
if self._transaction:
305-
# TODO: 6.0 - change this to be a TransactionError
306-
raise ClientError(
307-
"Explicit Transaction must be handled explicitly"
305+
raise TransactionError(
306+
self._transaction, "Explicit transaction already open"
308307
)
309308

310309
if self._auto_result:

src/neo4j/_sync/work/session.py

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)