Skip to content

Commit 6ec9f39

Browse files
committed
Resolve routing mode only after driver > 5.5 check
its not available for 4.4
1 parent 5d8223f commit 6ec9f39

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

graphdatascience/query_runner/neo4j_query_runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def run_retryable_cypher(
206206
params: Optional[dict[str, Any]] = None,
207207
database: Optional[str] = None,
208208
custom_error: bool = True,
209-
routing: Optional[neo4j.RoutingControl] = None,
209+
mode: Optional[QueryMode] = None,
210210
connectivity_retry_config: Optional[ConnectivityRetriesConfig] = None,
211211
) -> DataFrame:
212212
if not database:
@@ -215,8 +215,10 @@ def run_retryable_cypher(
215215
if self._NEO4J_DRIVER_VERSION < SemanticVersion(5, 5, 0):
216216
return self.run_cypher(query, params, database, custom_error, connectivity_retry_config)
217217

218-
if not routing:
218+
if not mode:
219219
routing = neo4j.RoutingControl.READ
220+
else:
221+
routing = mode.neo4j_routing()
220222

221223
try:
222224
return self._driver.execute_query(
@@ -240,9 +242,7 @@ def call_function(self, endpoint: str, params: Optional[CallParameters] = None,
240242
query = f"RETURN {endpoint}({params.placeholder_str()})"
241243

242244
# we can use retryable cypher as we expect all gds functions to be idempotent
243-
return self.run_retryable_cypher(
244-
query, params, custom_error=custom_error, routing=neo4j.RoutingControl.READ
245-
).squeeze()
245+
return self.run_retryable_cypher(query, params, custom_error=custom_error, mode=QueryMode.READ).squeeze()
246246

247247
def call_procedure(
248248
self,
@@ -263,7 +263,7 @@ def call_procedure(
263263

264264
def run_cypher_query() -> DataFrame:
265265
if retryable:
266-
return self.run_retryable_cypher(query, params, database, custom_error, routing=mode.neo4j_mode())
266+
return self.run_retryable_cypher(query, params, database, custom_error, mode=mode)
267267
else:
268268
return self.run_cypher(query, params, database, custom_error)
269269

graphdatascience/query_runner/query_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class QueryMode(str, Enum):
77
READ = "read"
88
WRITE = "write"
99

10-
def neo4j_mode(self) -> neo4j.RoutingControl:
10+
def neo4j_routing(self) -> neo4j.RoutingControl:
1111
if self == QueryMode.READ:
1212
return neo4j.RoutingControl.READ
1313
elif self == QueryMode.WRITE:

0 commit comments

Comments
 (0)