Skip to content

Commit eb15306

Browse files
committed
Handle empty graph case on remote write back
1 parent beb918b commit eb15306

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
## Bug fixes
1111

12-
* Fixed a bug, where sessions could not be created for AuraDB instances of tier `business-critical`
12+
* Fixed a bug, where sessions could not be created for AuraDB instances of tier `business-critical`.
13+
* Fixed a bug, where sessions would fail on write-back if the Graph was empty.
1314

1415

1516
## Improvements

graphdatascience/query_runner/session_query_runner.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,19 @@ def _remote_write_back(
195195
def run_write_back() -> DataFrame:
196196
return write_protocol.run_write_back(self._db_query_runner, write_back_params, yields)
197197

198-
if self._resolve_show_progress(logging):
199-
database_write_result = self._progress_logger.run_with_progress_logging(run_write_back, job_id, database)
200-
else:
201-
database_write_result = run_write_back()
198+
try:
199+
if self._resolve_show_progress(logging):
200+
database_write_result = self._progress_logger.run_with_progress_logging(
201+
run_write_back, job_id, database
202+
)
203+
else:
204+
database_write_result = run_write_back()
205+
except Exception as e:
206+
# catch the case nothing was needed to write-back (empty graph)
207+
# once we have the Arrow Endpoints V2, we could catch by first checking the jobs summary
208+
if "No entry with job id" in str(e) and gds_write_result.get("writeMillis", -1) == 0:
209+
return gds_write_result
210+
raise e
202211

203212
write_millis = (time.time() - write_back_start) * 1000
204213
gds_write_result["writeMillis"] = write_millis

graphdatascience/tests/integration/test_remote_graph_ops.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,19 @@ def test_remote_write_back_relationship_property_from_pathfinding_algo(
204204
)
205205

206206
assert result["relationshipsWritten"] == 1
207+
208+
209+
@pytest.mark.cloud_architecture
210+
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
211+
def test_empty_graph_write_back(
212+
gds_with_cloud_setup: AuraGraphDataScience,
213+
) -> None:
214+
G, result = gds_with_cloud_setup.graph.project(
215+
GRAPH_NAME, "MATCH (n:MISSING) RETURN gds.graph.project.remote(n, null)"
216+
)
217+
218+
assert G.node_count() == 0
219+
220+
result = gds_with_cloud_setup.wcc.write(G, writeProperty="wcc")
221+
222+
assert result["relationshipsWritten"] == 0

0 commit comments

Comments
 (0)