Skip to content

Commit ad83856

Browse files
authored
TypeError when passing Query to Transaction.run (#1171)
Raise `TypeError` instead of `ValueError` when passing a `Query` object to `Transaction.run`.
1 parent ea8d1fa commit ad83856

File tree

5 files changed

+5
-6
lines changed

5 files changed

+5
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ 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+
- `TypeError` instead of `ValueError` when passing a `Query` object to `Transaction.run`.
4344
- `TransactionError` (subclass of `DriverError`) instead of `ClientError` (subclass of `Neo4jError`) when calling
4445
`session.run()` while an explicit transaction is active on that session.
4546
- This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side

src/neo4j/_async/work/transaction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ async def run(
173173
:returns: a new :class:`neo4j.AsyncResult` object
174174
"""
175175
if isinstance(query, Query):
176-
# TODO: 6.0 - make this a TypeError and remove lint exception
177-
raise ValueError("Query object is only supported for session.run") # noqa: TRY004
176+
raise TypeError("Query object is only supported for session.run")
178177

179178
if self._closed_flag:
180179
raise TransactionError(self, "Transaction closed")

src/neo4j/_sync/work/transaction.py

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/unit/async_/work/test_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async def test_transaction_run_takes_no_query_object(async_fake_connection):
141141
tx = AsyncTransaction(
142142
async_fake_connection, 2, None, on_closed, on_error, on_cancel, None
143143
)
144-
with pytest.raises(ValueError):
144+
with pytest.raises(TypeError):
145145
await tx.run(Query("RETURN 1"))
146146

147147

tests/unit/sync/work/test_transaction.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)