Skip to content

fix add_edge_to_view leaving edge_id to -1 in SQL - #331

Open
TeunHuijben wants to merge 1 commit into
royerlab:mainfrom
TeunHuijben:fix-edge-id-sql-after-edge-revival
Open

fix add_edge_to_view leaving edge_id to -1 in SQL#331
TeunHuijben wants to merge 1 commit into
royerlab:mainfrom
TeunHuijben:fix-edge-id-sql-after-edge-revival

Conversation

@TeunHuijben

Copy link
Copy Markdown
Contributor

Fix: add_edge_to_view leaves the local edge_id as -1 on a SQL root

Reviving a soft-deleted edge into a view with add_edge_to_view left the view's local copy of the edge with edge_id = -1 (the placeholder) when the root is a SQLGraph. The id map was updated correctly, so view.edge_id(a, b) returned the right root id while view.edge_attrs() still showed -1 for that row — the two disagreed, and any read of that edge's attributes by edge id hit zero rows.

Reproduction

import polars as pl
from tracksdata.graph import SQLGraph

g = SQLGraph(drivername="sqlite", database=":memory:")
g.add_edge_attr_key("weight", pl.Float64)
a = g.add_node({"t": 0})
b = g.add_node({"t": 1})
edge_id = g.add_edge(a, b, {"weight": 1.5})

view = g.filter().subgraph()
view.remove_edge_from_view(a, b)   # hide the edge in the view only
view.add_edge_to_view(a, b)        # bring it back

print(view.edge_id(a, b))                      # 1    -> id map is correct
print(view.edge_attrs()["edge_id"].to_list())  # [-1]  -> local row is wrong
print(view.edges[edge_id]["weight"])           # ValueError
ValueError: can only call '.item()' if the Series is of length 1, or an explicit
index is provided (Series is of length 0)

The root graph is fine throughout, and the in-memory backends are unaffected: there the view reuses the root's edge payload by reference, so the id comes along for free. _add_edge_local only breaks for a non-rx root, where it re-fetches the edge attrs, drops edge_id, and never stamps it back.

Fix

Stamp the root edge id into the reconstructed payload in _add_edge_local, the same way add_edge and bulk_add_edges already do.

Test

test_add_edge_to_view_keeps_edge_id — revive an edge into a view, then assert the id map, the edge_attrs() row, and a read by edge id all agree. Parametrized over all three backends; it failed on SQLGraph only before the fix.

@TeunHuijben
TeunHuijben requested a review from JoOkuma July 30, 2026 20:55
@TeunHuijben TeunHuijben linked an issue Jul 30, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reviving an edge on SQL-backend mislabels ID in the view

1 participant