Skip to content

ValueError on invalid access_mode #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
- Python 3.7, 3.8, and 3.9 support has been dropped.
- Remove deprecated package alias `neo4j-driver`. Use `pip install neo4j` instead.
- Remove `setup.py`. Please use a recent enough packaging/build tool that supports `pyproject.toml`
- Changed errors raised under certain circumstances
- `access_mode` configuration option
- `ValueError` on invalid value (instead of `ClientError`)
- Consistently check the value (also for non-routing drivers)


## Version 5.28
Expand Down
15 changes: 3 additions & 12 deletions src/neo4j/_async/io/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
from ..._exceptions import BoltError
from ..._routing import RoutingTable
from ...api import (
check_access_mode,
READ_ACCESS,
WRITE_ACCESS,
)
from ...exceptions import (
ClientError,
Expand Down Expand Up @@ -669,6 +669,7 @@ async def acquire(
):
# The access_mode and database is not needed for a direct connection,
# it's just there for consistency.
access_mode = check_access_mode(access_mode)
log.debug(
"[#0000] _: <POOL> acquire direct connection, "
"access_mode=%r, database=%r",
Expand Down Expand Up @@ -1063,8 +1064,6 @@ async def ensure_routing_table_is_fresh(
:returns: `True` if an update was required, `False` otherwise.
"""
from ...api import READ_ACCESS

async with self.refresh_lock:
for database_ in list(self.routing_tables.keys()):
# Remove unused databases in the routing table
Expand Down Expand Up @@ -1111,8 +1110,6 @@ async def wrapped_database_callback(database: str | None) -> None:

async def _select_address(self, *, access_mode, database):
"""Select the address with the fewest in-use connections."""
from ...api import READ_ACCESS

async with self.refresh_lock:
routing_table = self.routing_tables.get(database)
if routing_table:
Expand Down Expand Up @@ -1149,19 +1146,13 @@ async def acquire(
unprepared=False,
database_callback=None,
):
if access_mode not in {WRITE_ACCESS, READ_ACCESS}:
# TODO: 6.0 - change this to be a ValueError
raise ClientError(f"Non valid 'access_mode'; {access_mode}")
access_mode = check_access_mode(access_mode)
if not timeout:
# TODO: 6.0 - change this to be a ValueError
raise ClientError(
f"'timeout' must be a float larger than 0; {timeout}"
)

from ...api import check_access_mode

access_mode = check_access_mode(access_mode)

target_database = database.name

async def wrapped_database_callback(new_database):
Expand Down
15 changes: 3 additions & 12 deletions src/neo4j/_sync/io/_pool.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/neo4j/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ def parse_neo4j_uri(uri):

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

return access_mode

Expand Down