From 856529f39de0862fccb4595535a75bdd03b37b16 Mon Sep 17 00:00:00 2001 From: Shaun Patterson Date: Sat, 21 Nov 2026 11:20:08 -0500 Subject: [PATCH] fix(#421): JVM new_edges takes a vertex or document as new_edge does new_edges wrote each source and destination with str(), so a Vertex became its repr and the engine refused it as an RID. It now reads the RID of a record wrapper with get_rid(), as the native wheel does, and keeps str() for a string or a Java RID. --- src/arcadedb/graph_batch.py | 16 +++++++++++----- tests/test_graph_batch.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/arcadedb/graph_batch.py b/src/arcadedb/graph_batch.py index dbd9ba7c..7008c01e 100644 --- a/src/arcadedb/graph_batch.py +++ b/src/arcadedb/graph_batch.py @@ -375,6 +375,12 @@ def new_edge( f"Failed to buffer batch edge '{edge_type}': {e}" ) from e + @staticmethod + def _rid_text(value) -> str: + """The RID text of a vertex or document (a record wrapper), or the text of a RID given as a string or a Java ``RID``.""" + get_rid = getattr(value, "get_rid", None) + return get_rid() if get_rid is not None else str(value) + def new_edges( self, source_rids, @@ -387,8 +393,8 @@ def new_edges( The bulk counterpart of :meth:`new_edge` (which costs one boundary crossing per edge — measured ~24x slower than Java-native for large - edge lists). RIDs may be strings ("#1:0") or objects with a string - representation. + edge lists). Each source and destination is a RID string ("#1:0"), a + Java ``RID``, or a vertex or document, as for :meth:`new_edge`. Args: source_rids: Sequence of source vertex RIDs. @@ -453,8 +459,8 @@ def new_edges( # copy; a Python list of N strings would be converted # element-by-element by JPype and eat the batching win. # Chunked so huge ingests never build one giant string. - sources = [str(r) for r in source_rids] - dests = [str(r) for r in destination_rids] + sources = [self._rid_text(r) for r in source_rids] + dests = [self._rid_text(r) for r in destination_rids] for start in range(0, len(sources), self._BULK_CHUNK): edge_batcher.newEdgesJoined( self._java_graph_batch, @@ -467,7 +473,7 @@ def new_edges( rows = [] tagged = False # a value that needs the tagged text; False keeps the untagged code of before for src, dst, p in zip(source_rids, destination_rids, properties): - row = {"_src": str(src), "_dst": str(dst)} + row = {"_src": self._rid_text(src), "_dst": self._rid_text(dst)} for key, value in (p or {}).items(): ok = type(key) is str and key not in ("_src", "_dst") if ok and not json_bulk_scalar_ok(value): diff --git a/tests/test_graph_batch.py b/tests/test_graph_batch.py index dc95fa91..b5d14283 100644 --- a/tests/test_graph_batch.py +++ b/tests/test_graph_batch.py @@ -381,6 +381,27 @@ def test_graph_batch_edge_keeps_a_null_in_a_declared_property(temp_db_path, bulk assert [(r.get("weight"), r.get("note")) for r in rows] == [(None, "hello")] +@pytest.mark.parametrize("with_properties", [False, True], ids=["plain", "properties"]) +def test_new_edges_takes_vertex_objects_as_new_edge_does(temp_db_path, with_properties): + """new_edge accepts a Vertex or its RID. new_edges stringified each item, so a Vertex became + "" and the engine refused it as an invalid RID.""" + with arcadedb.create_database(temp_db_path) as db: + _declared_edge_types(db) + with db.transaction(): + a = db.new_vertex("P").set("id", 1).save() + b = db.new_vertex("P").set("id", 2).save() + c = db.new_vertex("P").set("id", 3).save() + properties = [{"note": "x"}] * 3 if with_properties else None + with db.graph_batch(parallel_flush=False) as batch: + batch.new_edges( + [a, b.get_rid(), c], "ViaBulk", [b, c, a.get_identity()], properties + ) + rows = db.query( + "sql", "SELECT out.id AS src, in.id AS dst FROM ViaBulk ORDER BY src" + ).to_list() + assert [(r.get("src"), r.get("dst")) for r in rows] == [(1, 2), (2, 3), (3, 1)] + + def test_graph_batch_edge_refuses_an_out_of_range_short(temp_db_path): """ArcadeData/arcadedb#9019, fixed in 26.10.1 (upstream PR #9108): a GraphBatch edge skipped the declared property's conversion, so 40000 in a SHORT was stored as -25536.