Skip to content

Commit 5783295

Browse files
committed
ValueError on invalid connection_acquisition_timeout
- `ValueError` on invalid values (instead of `ClientError`) - Consistently restrict the value to be strictly positive
1 parent aa99b7b commit 5783295

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
66
- Python 3.7, 3.8, and 3.9 support has been dropped.
77
- Remove deprecated package alias `neo4j-driver`. Use `pip install neo4j` instead.
88
- Remove `setup.py`. Please use a recent enough packaging/build tool that supports `pyproject.toml`
9+
- Changed errors raised under certain circumstances
10+
- `connection_acquisition_timeout` configuration option
11+
- `ValueError` on invalid values (instead of `ClientError`)
12+
- Consistently restrict the value to be strictly positive
913

1014

1115
## Version 5.28

src/neo4j/_async/io/_pool.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import abc
2020
import asyncio
2121
import logging
22+
import math
2223
import typing as t
2324
from collections import (
2425
defaultdict,
@@ -669,6 +670,7 @@ async def acquire(
669670
):
670671
# The access_mode and database is not needed for a direct connection,
671672
# it's just there for consistency.
673+
_check_acquisition_timeout(timeout)
672674
log.debug(
673675
"[#0000] _: <POOL> acquire direct connection, "
674676
"access_mode=%r, database=%r",
@@ -969,6 +971,7 @@ async def update_routing_table(
969971
970972
:raise neo4j.exceptions.ServiceUnavailable:
971973
"""
974+
_check_acquisition_timeout(acquisition_timeout)
972975
async with self.refresh_lock:
973976
routing_table = await self.get_routing_table(database)
974977
if routing_table is not None:
@@ -1152,11 +1155,7 @@ async def acquire(
11521155
if access_mode not in {WRITE_ACCESS, READ_ACCESS}:
11531156
# TODO: 6.0 - change this to be a ValueError
11541157
raise ClientError(f"Non valid 'access_mode'; {access_mode}")
1155-
if not timeout:
1156-
# TODO: 6.0 - change this to be a ValueError
1157-
raise ClientError(
1158-
f"'timeout' must be a float larger than 0; {timeout}"
1159-
)
1158+
_check_acquisition_timeout(timeout)
11601159

11611160
from ...api import check_access_mode
11621161

@@ -1253,3 +1252,23 @@ async def on_write_failure(self, address, database):
12531252
if table is not None:
12541253
table.writers.discard(address)
12551254
log.debug("[#0000] _: <POOL> table=%r", self.routing_tables)
1255+
1256+
1257+
def _check_acquisition_timeout(timeout: object) -> None:
1258+
if isinstance(timeout, int):
1259+
if timeout <= 0:
1260+
raise ValueError(
1261+
f"Connection acquisition timeout must be > 0, got {timeout}"
1262+
)
1263+
elif isinstance(timeout, float):
1264+
if math.isnan(timeout):
1265+
raise ValueError("Connection acquisition timeout must not be NaN")
1266+
if timeout <= 0:
1267+
raise ValueError(
1268+
f"Connection acquisition timeout must be > 0, got {timeout}"
1269+
)
1270+
else:
1271+
raise TypeError(
1272+
"Connection acquisition timeout must be a number, "
1273+
f"got {type(timeout)}"
1274+
)

src/neo4j/_sync/io/_pool.py

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

0 commit comments

Comments
 (0)