Skip to content

Commit eedcfc7

Browse files
committed
ValueError on invalid access_mode
1 parent aa99b7b commit eedcfc7

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
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+
- `access_mode` configuration option
11+
- `ValueError` on invalid value (instead of `ClientError`)
12+
- Consistently check the value (also for non-routing drivers)
913

1014

1115
## Version 5.28

‎src/neo4j/_async/io/_pool.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
from ..._exceptions import BoltError
4646
from ..._routing import RoutingTable
4747
from ...api import (
48+
check_access_mode,
4849
READ_ACCESS,
49-
WRITE_ACCESS,
5050
)
5151
from ...exceptions import (
5252
ClientError,
@@ -669,6 +669,7 @@ async def acquire(
669669
):
670670
# The access_mode and database is not needed for a direct connection,
671671
# it's just there for consistency.
672+
access_mode = check_access_mode(access_mode)
672673
log.debug(
673674
"[#0000] _: <POOL> acquire direct connection, "
674675
"access_mode=%r, database=%r",
@@ -1063,8 +1064,6 @@ async def ensure_routing_table_is_fresh(
10631064
10641065
:returns: `True` if an update was required, `False` otherwise.
10651066
"""
1066-
from ...api import READ_ACCESS
1067-
10681067
async with self.refresh_lock:
10691068
for database_ in list(self.routing_tables.keys()):
10701069
# Remove unused databases in the routing table
@@ -1111,8 +1110,6 @@ async def wrapped_database_callback(database: str | None) -> None:
11111110

11121111
async def _select_address(self, *, access_mode, database):
11131112
"""Select the address with the fewest in-use connections."""
1114-
from ...api import READ_ACCESS
1115-
11161113
async with self.refresh_lock:
11171114
routing_table = self.routing_tables.get(database)
11181115
if routing_table:
@@ -1149,19 +1146,13 @@ async def acquire(
11491146
unprepared=False,
11501147
database_callback=None,
11511148
):
1152-
if access_mode not in {WRITE_ACCESS, READ_ACCESS}:
1153-
# TODO: 6.0 - change this to be a ValueError
1154-
raise ClientError(f"Non valid 'access_mode'; {access_mode}")
1149+
access_mode = check_access_mode(access_mode)
11551150
if not timeout:
11561151
# TODO: 6.0 - change this to be a ValueError
11571152
raise ClientError(
11581153
f"'timeout' must be a float larger than 0; {timeout}"
11591154
)
11601155

1161-
from ...api import check_access_mode
1162-
1163-
access_mode = check_access_mode(access_mode)
1164-
11651156
target_database = database.name
11661157

11671158
async def wrapped_database_callback(new_database):

‎src/neo4j/_sync/io/_pool.py

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

‎src/neo4j/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,11 @@ def parse_neo4j_uri(uri):
603603

604604
# TODO: 6.0 - make this function private
605605
def check_access_mode(access_mode):
606-
if access_mode is None:
607-
return WRITE_ACCESS
608606
if access_mode not in {READ_ACCESS, WRITE_ACCESS}:
609-
msg = f"Unsupported access mode {access_mode}"
610-
raise ConfigurationError(msg)
607+
raise ValueError(
608+
f"Unsupported access mode {access_mode}, must be one of "
609+
f"'{READ_ACCESS}' or '{WRITE_ACCESS}'."
610+
)
611611

612612
return access_mode
613613

0 commit comments

Comments
 (0)