Skip to content

Commit 98e1800

Browse files
committed
ValueError on invalid access_mode
1 parent aa99b7b commit 98e1800

File tree

4 files changed

+10
-28
lines changed

4 files changed

+10
-28
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ 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+
- `ValueError` if the passed `access_mode` config has an invalid value (instead of `ClientError`)
911

1012

1113
## Version 5.28

src/neo4j/_async/io/_pool.py

+2-12
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,
@@ -1063,8 +1063,6 @@ async def ensure_routing_table_is_fresh(
10631063
10641064
:returns: `True` if an update was required, `False` otherwise.
10651065
"""
1066-
from ...api import READ_ACCESS
1067-
10681066
async with self.refresh_lock:
10691067
for database_ in list(self.routing_tables.keys()):
10701068
# Remove unused databases in the routing table
@@ -1111,8 +1109,6 @@ async def wrapped_database_callback(database: str | None) -> None:
11111109

11121110
async def _select_address(self, *, access_mode, database):
11131111
"""Select the address with the fewest in-use connections."""
1114-
from ...api import READ_ACCESS
1115-
11161112
async with self.refresh_lock:
11171113
routing_table = self.routing_tables.get(database)
11181114
if routing_table:
@@ -1149,19 +1145,13 @@ async def acquire(
11491145
unprepared=False,
11501146
database_callback=None,
11511147
):
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}")
1148+
access_mode = check_access_mode(access_mode)
11551149
if not timeout:
11561150
# TODO: 6.0 - change this to be a ValueError
11571151
raise ClientError(
11581152
f"'timeout' must be a float larger than 0; {timeout}"
11591153
)
11601154

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

11671157
async def wrapped_database_callback(new_database):

src/neo4j/_sync/io/_pool.py

+2-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/neo4j/api.py

+4-4
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)