Skip to content

Commit 66b3131

Browse files
committed
Fix bookmarks usage for retryable cypher
1 parent fafc37d commit 66b3131

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
## Bug fixes
1111

1212
- Fix reporting error based on http responses from the Aura-API with an invalid JSON body. Earlier the client would report JSONDecodeError instead of showing the actual issue.
13+
- Fixed a bug where retryable queries wouldnt work with bookmarks.
1314

1415
## Improvements
1516

graphdatascience/query_runner/neo4j_query_runner.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,20 @@ def run_retryable_cypher(
229229
routing = mode.neo4j_routing()
230230

231231
try:
232-
return self._driver.execute_query(
232+
bookmark_manager = neo4j.GraphDatabase.bookmark_manager(self.bookmarks())
233+
234+
result = self._driver.execute_query(
233235
query_=query,
234236
parameters_=params,
235237
database_=database,
236238
result_transformer_=neo4j.Result.to_df,
237-
bookmark_manager_=self.bookmarks(),
239+
bookmark_manager_=bookmark_manager,
238240
routing_=routing,
239241
)
242+
243+
self._last_bookmarks = neo4j.Bookmarks.from_raw_values(bookmark_manager.get_bookmarks())
244+
245+
return result
240246
except Exception as e:
241247
if custom_error:
242248
Neo4jQueryRunner.handle_driver_exception(self._driver, e)

graphdatascience/tests/integration/test_database_ops.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ def test_run_read_cypher(gds: GraphDataScience) -> None:
167167
assert len(result) > 10
168168

169169

170+
def test_run_cypher_with_bookmarks(gds: GraphDataScience) -> None:
171+
gds.run_cypher("RETURN true")
172+
bookmarks_from_standard = gds.last_bookmarks()
173+
gds.set_bookmarks(bookmarks_from_standard)
174+
175+
assert bookmarks_from_standard is not None
176+
177+
gds.run_cypher("RETURN true", retryable=True)
178+
bookmarks_from_retryable = gds.last_bookmarks()
179+
180+
assert bookmarks_from_retryable is not None
181+
assert bookmarks_from_retryable != bookmarks_from_standard
182+
183+
gds.set_bookmarks(bookmarks_from_retryable)
184+
185+
gds.run_cypher("RETURN true", retryable=True)
186+
gds.run_cypher("RETURN true", retryable=False)
187+
188+
170189
def test_server_version(gds: GraphDataScience) -> None:
171190
cached_server_version = gds._server_version
172191
server_version_string = gds.version()

0 commit comments

Comments
 (0)