Skip to content

Surface DatabaseNotFound on routing message to user #519

New issue

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

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

Already on GitHub? # to your account

Merged
merged 3 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions neo4j/io/_bolt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def route(self, database):

def fail(md):
from neo4j._exceptions import BoltRoutingError
if md.get("code") == "Neo.ClientError.Procedure.ProcedureNotFound":
code = md.get("code")
if code == "Neo.ClientError.Database.DatabaseNotFound":
return # surface this error to the user
elif code == "Neo.ClientError.Procedure.ProcedureNotFound":
raise BoltRoutingError("Server does not support routing", self.unresolved_address)
else:
raise BoltRoutingError("Routing support broken on server", self.unresolved_address)
Expand Down Expand Up @@ -512,7 +515,10 @@ def route(self, database):

def fail(md):
from neo4j._exceptions import BoltRoutingError
if md.get("code") == "Neo.ClientError.Procedure.ProcedureNotFound":
code = md.get("code")
if code == "Neo.ClientError.Database.DatabaseNotFound":
return # surface this error to the user
elif code == "Neo.ClientError.Procedure.ProcedureNotFound":
raise BoltRoutingError("Server does not support routing", self.unresolved_address)
else:
raise BoltRoutingError("Routing support broken on server", self.unresolved_address)
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_neo4j_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def test_test_multi_db_specify_database(neo4j_uri, auth, target):
assert "Database name parameter for selecting database is not supported in Bolt Protocol Version(3, 0)." in error.args[0]
except ClientError as error:
# FAILURE {'code': 'Neo.ClientError.Database.DatabaseNotFound' - This message is sent from the server
assert error.args[0] == "Unable to get a routing table for database 'test_database' because this database does not exist"
assert error.code == "Neo.ClientError.Database.DatabaseNotFound"
assert "test_database" in error.message


def test_neo4j_multi_database_support_create(neo4j_uri, auth, target, requires_bolt_4x):
Expand Down