Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
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
6 changes: 6 additions & 0 deletions bindings/python/docs/api/graph_batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ was also slower than inserting one vector per `db.command(...)`.

Buffer an edge for creation during flush/close.

!!! warning "Declared edge properties"
An edge buffered with properties skips the declared property's conversion and the type's
constraints: a `None` followed by another property is stored as `-1` in an `INTEGER`, and
`40000` in a `SHORT` as `-25536`. Write edges with declared properties through
`Vertex.new_edge` instead; see [Known Engine Issues](../guide/known-issues.md).

### `new_edges(source_rids, edge_type, destination_rids, properties=None)`

Buffer many edges with one JPype crossing per call: the bulk counterpart of
Expand Down
36 changes: 36 additions & 0 deletions bindings/python/docs/guide/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,39 @@ Equality lookups use the hash index and work, and SQL answers the same range by
Index a property that you query by range with `UNIQUE` or `NOTUNIQUE` (an `LSM_TREE` index),
which serves both equality and ranges; a property cannot hold a hash index and an `LSM_TREE`
index at once. Otherwise run the range in SQL.

## `GraphBatch` edges with declared properties skip conversion and constraints

ArcadeDB [#9018](https://github.com/ArcadeData/arcadedb/issues/9018) and
[#9019](https://github.com/ArcadeData/arcadedb/issues/9019); measured through the bindings
on a 26.10.1 snapshot. The Java reproductions in the two issues show the same on 26.9.1.

An edge written through `GraphBatch` (`batch.new_edge(...)` with properties, or
`batch.new_edges(..., properties=[...])`) is serialized without the declared property's
conversion or the type's constraints. With an edge type that declares `weight INTEGER`,
`small SHORT`, and `note STRING`:

- `weight=None, note="hello"` is stored as `weight = -1`: the null is written as a type tag
with no value, so the bytes of the next property are read as the value. A null in the
last property reads back as null but logs `Possible corrupted record` when the edge is read.
- `small=40000` is stored as `-25536`.
- `MANDATORY`, `MIN`, and `REGEXP` are not checked and `DEFAULT` is not applied.

`Vertex.new_edge(...)` converts and validates the same values: the null stays null and
40000 is refused. A batch that also holds an edge of a second type stores the null
correctly, which is not something to rely on.

Write edges that carry declared properties through the vertex API, in a transaction. Edge
types with no declared properties, or whose properties you give already converted and never
`None`, are not affected, and `GraphBatch` stays the fast path for those.

```python
with db.transaction():
a = db.new_vertex("P").set("id", 1).save()
b = db.new_vertex("P").set("id", 2).save()
a.new_edge("Knows", b, weight=None, note="hello").save() # null stays null
```

Tests: `test_vertex_new_edge_keeps_a_null_and_refuses_an_out_of_range_short` checks this
workaround, and the strict `xfail` tests next to it start failing the suite when an engine
fix reaches the wheel, which is the cue to remove this entry.
91 changes: 91 additions & 0 deletions bindings/python/tests/test_graph_batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import arcadedb_embedded as arcadedb
import pytest


def test_graph_batch_creates_vertices_and_edges(temp_db_path):
Expand Down Expand Up @@ -312,3 +313,93 @@ def count(language, query):
)
tag = db.query("sql", "SELECT FROM Tag WHERE k = 0").first().get_vertex()
assert tag.get_in_edges("TaggedWith") == []


def _declared_edge_types(db):
"""Edge types that declare a nullable INTEGER, a SHORT, and a STRING, one per write path."""
db.command("sql", "CREATE VERTEX TYPE P")
for name in ("ViaRecord", "ViaBatch", "ViaBulk"):
db.command("sql", f"CREATE EDGE TYPE {name}")
db.command("sql", f"CREATE PROPERTY {name}.weight INTEGER")
db.command("sql", f"CREATE PROPERTY {name}.small SHORT")
db.command("sql", f"CREATE PROPERTY {name}.note STRING")


def test_vertex_new_edge_keeps_a_null_and_refuses_an_out_of_range_short(temp_db_path):
"""The workaround in known-issues.md: write edges that carry declared
properties through Vertex.new_edge, which converts and validates them."""
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()
a.new_edge("ViaRecord", b, weight=None, note="hello").save()
rows = db.query("sql", "SELECT weight, note FROM ViaRecord").to_list()
assert [(r.get("weight"), r.get("note")) for r in rows] == [(None, "hello")]

with pytest.raises(Exception): # noqa: B017 - a Java IllegalArgumentException
with db.transaction():
a.new_edge("ViaRecord", b, small=40000).save()
assert (
db.query("sql", "SELECT count(*) AS n FROM ViaRecord").first().get("n") == 1
)


@pytest.mark.xfail(
strict=True,
reason="ArcadeData/arcadedb#9018: GraphBatch writes a null in a declared edge property "
"as a type tag with no value, so the bytes of the next property are read as its value",
)
@pytest.mark.parametrize("bulk", [False, True], ids=["new_edge", "new_edges"])
def test_graph_batch_edge_keeps_a_null_in_a_declared_property(temp_db_path, bulk):
"""Strict xfail, as test_restore_sql.py did for #6096: when an engine fix
reaches the wheel this starts passing, the suite fails, and the known-issues.md
entry and the GraphBatch API page caution are removed. The null must be
followed by another property: a null written last reads back as null."""
with arcadedb.create_database(temp_db_path) as db:
_declared_edge_types(db)
edge_type = "ViaBulk" if bulk else "ViaBatch"
with db.transaction():
a = db.new_vertex("P").set("id", 1).save()
b = db.new_vertex("P").set("id", 2).save()
with db.graph_batch(parallel_flush=False) as batch:
if bulk:
batch.new_edges(
[a.get_rid()],
edge_type,
[b.get_rid()],
properties=[{"weight": None, "note": "hello"}],
)
else:
batch.new_edge(
a.get_rid(), edge_type, b.get_rid(), weight=None, note="hello"
)
query = f"SELECT weight, note FROM {edge_type}" # nosec B608 - fixed type names
rows = db.query("sql", query).to_list()
assert [(r.get("weight"), r.get("note")) for r in rows] == [(None, "hello")]


@pytest.mark.xfail(
strict=True,
reason="ArcadeData/arcadedb#9019: a GraphBatch edge skips the declared property's "
"conversion and constraints, so 40000 in a SHORT is stored as -25536",
)
def test_graph_batch_edge_refuses_an_out_of_range_short(temp_db_path):
"""Strict xfail, same reason as above. A fixed engine either refuses the value
or stores it as the record API does; what it must not do is wrap it."""
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()
try:
with db.graph_batch(parallel_flush=False) as batch:
batch.new_edge(a.get_rid(), "ViaBatch", b.get_rid(), small=40000)
refused = False
except Exception: # noqa: BLE001 - the engine's refusal, whatever its Java type
refused = True
stored = [
r.get("small")
for r in db.query("sql", "SELECT small FROM ViaBatch").to_list()
]
assert refused and stored == []
Loading