Skip to content

Commit 7154681

Browse files
New ConnectionAcquisitionTimeoutError instead of ClientError (#1169)
Raise a new `ConnectionAcquisitionTimeoutError` (subclass of `DriverError`) instead of `ClientError` (subclass of `Neo4jError`) when the connection acquisition timeout is exceeded. This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side errors. Signed-off-by: Rouven Bauer <[email protected]> Co-authored-by: Andy Heap <[email protected]>
1 parent ad83856 commit 7154681

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
3030
- `Version`'s additional methods were undocumented and shouldn't have been used
3131
- Changed errors raised under certain circumstances
3232
- `ConfigurationError` if the passed `auth` parameters is not valid (instead of `AuthError`)
33-
- This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side errors.
33+
- This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side
34+
errors.
3435
- `access_mode` configuration option
3536
- `ValueError` on invalid value (instead of `ClientError`)
3637
- Consistently check the value (also for non-routing drivers)
@@ -40,6 +41,10 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
4041
- `connection_acquisition_timeout` configuration option
4142
- `ValueError` on invalid values (instead of `ClientError`)
4243
- Consistently restrict the value to be strictly positive
44+
- New `ConnectionAcquisitionTimeoutError` (subclass of `DriverError`) instead of `ClientError`
45+
(subclass of `Neo4jError`) the timeout is exceeded.
46+
- This improves the differentiation between `DriverError` for client-side errors and `Neo4jError` for server-side
47+
errors.
4348
- `TypeError` instead of `ValueError` when passing a `Query` object to `Transaction.run`.
4449
- `TransactionError` (subclass of `DriverError`) instead of `ClientError` (subclass of `Neo4jError`) when calling
4550
`session.run()` while an explicit transaction is active on that session.

docs/source/api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,10 @@ Client-side errors
21192119

21202120
* :class:`neo4j.exceptions.CertificateConfigurationError`
21212121

2122+
* :class:`neo4j.exceptions.ConnectionPoolError`
2123+
2124+
* :class:`neo4j.exceptions.ConnectionAcquisitionTimeoutError`
2125+
21222126

21232127
.. autoexception:: neo4j.exceptions.DriverError()
21242128
:show-inheritance:

src/neo4j/_async/io/_pool.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
READ_ACCESS,
5151
)
5252
from ...exceptions import (
53-
ClientError,
5453
ConfigurationError,
54+
ConnectionAcquisitionTimeoutError,
5555
DriverError,
5656
Neo4jError,
5757
ReadServiceUnavailable,
@@ -412,8 +412,7 @@ async def health_check(connection_, deadline_):
412412
or not await self.cond.wait(timeout)
413413
):
414414
log.debug("[#0000] _: <POOL> acquisition timed out")
415-
# TODO: 6.0 - change this to be a DriverError (or subclass)
416-
raise ClientError(
415+
raise ConnectionAcquisitionTimeoutError(
417416
"failed to obtain a connection from the pool within "
418417
f"{deadline.original_timeout!r}s (timeout)"
419418
)

src/neo4j/_sync/io/_pool.py

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

src/neo4j/exceptions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
+ ConfigurationError
5757
+ AuthConfigurationError
5858
+ CertificateConfigurationError
59+
+ ConnectionPoolError
60+
+ ConnectionAcquisitionTimeoutError
5961
"""
6062

6163
from __future__ import annotations
@@ -77,6 +79,8 @@
7779
"CertificateConfigurationError",
7880
"ClientError",
7981
"ConfigurationError",
82+
"ConnectionAcquisitionTimeoutError",
83+
"ConnectionPoolError",
8084
"ConstraintError",
8185
"CypherSyntaxError",
8286
"CypherTypeError",
@@ -1190,3 +1194,18 @@ class AuthConfigurationError(ConfigurationError):
11901194
# DriverError > ConfigurationError > CertificateConfigurationError
11911195
class CertificateConfigurationError(ConfigurationError):
11921196
"""Raised when there is an error with the certificate configuration."""
1197+
1198+
1199+
# DriverError > ConnectionPoolError
1200+
class ConnectionPoolError(DriverError):
1201+
"""Raised when the connection pool encounters an error."""
1202+
1203+
1204+
# DriverError > ConnectionPoolError > ConnectionAcquisitionTimeoutError
1205+
class ConnectionAcquisitionTimeoutError(ConnectionPoolError):
1206+
"""
1207+
Raised when no connection became available in time.
1208+
1209+
The amount of time is determined by the connection acquisition timeout
1210+
configuration option.
1211+
"""

tests/unit/async_/io/test_direct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from neo4j._deadline import Deadline
2828
from neo4j.auth_management import AsyncAuthManagers
2929
from neo4j.exceptions import (
30-
ClientError,
30+
ConnectionAcquisitionTimeoutError,
3131
ServiceUnavailable,
3232
)
3333

@@ -206,7 +206,7 @@ async def test_pool_max_conn_pool_size(async_fake_connection_generator):
206206
address = neo4j.Address(("127.0.0.1", 7687))
207207
await pool._acquire(address, None, Deadline(0), None)
208208
assert pool.in_use_connection_count(address) == 1
209-
with pytest.raises(ClientError):
209+
with pytest.raises(ConnectionAcquisitionTimeoutError):
210210
await pool._acquire(address, None, Deadline(0), None)
211211
assert pool.in_use_connection_count(address) == 1
212212

tests/unit/sync/io/test_direct.py

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

0 commit comments

Comments
 (0)