refactor(graph): migrate Dependencies & Diagram to nx.MultiDiGraph (#1492)#1508
Open
dimitri-yatsenko wants to merge 1 commit into
Open
refactor(graph): migrate Dependencies & Diagram to nx.MultiDiGraph (#1492)#1508dimitri-yatsenko wants to merge 1 commit into
dimitri-yatsenko wants to merge 1 commit into
Conversation
Member
Author
|
Paired docs PR: datajoint/datajoint-docs#215 — updates the diagram-notation docs (renamed FKs render as orange edges with a rename tooltip instead of alias-node dots) and adds a renamed-primary example showing the line-style semantics are retained. The docs PR re-executed its notebooks against this branch, so it is gated on this shipping in v2.3.2 and must not merge until the release. |
dimitri-yatsenko
force-pushed
the
fix/1492-multidigraph
branch
2 times, most recently
from
July 18, 2026 17:00
d465dca to
fa7e9dd
Compare
…1492) Retire the integer "alias node" workaround for renamed / multiple foreign keys between the same pair of tables. A plain DiGraph allows one edge per node pair, so a renamed FK was split through an integer alias node, with ~14 .isdigit() special-cases (diagram.py) plus 5 in table.py to see through them. MultiDiGraph represents parallel edges natively, so the workaround is removed entirely. Edges are keyed by the FK's child-side attribute tuple (in declaration order) — unique among parallel edges (all FKs to a parent reference its primary key, so they differ only in referencing columns) and derived purely from the schema. Because the key is stable and meaningful, graph merges are idempotent: combining diagrams (Diagram + Diagram) can't duplicate a shared FK, so no defensive dedup is needed. - Dependencies/Diagram subclass nx.MultiDiGraph; load() adds one keyed edge per FK; topo_sort drops alias-collapse; cascade()/trace() rebuild via MultiDiGraph. - Propagation walkers merged their alias/direct branches into one loop over parallel edges; _find_real_edge_props -> _edge_props (direct lookup). - dependencies.parents()/children() return a parallel-safe list[(node, props)]; Table.parents/children/descendants/ancestors/parts drop the .isdigit() handling. - Rendering: a renamed FK draws as an orange (#FF8800) edge with the column renames in a hover tooltip (dot/SVG) and a linkStyle recolor (mermaid), instead of the alias-node dot. Orange is layered on top of the existing line semantics (solid=primary, dashed=secondary, thick=1:1, thin=multi). _AliasNode removed. - _apply_collapse keeps parallel edges between expanded tables (keyed) while merging edges into a collapsed schema node to a single arrow.
dimitri-yatsenko
force-pushed
the
fix/1492-multidigraph
branch
from
July 18, 2026 17:09
fa7e9dd to
39f8f81
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1492.
Migrates
DependenciesandDiagramfromnx.DiGraphtonx.MultiDiGraph, retiring the integer "alias node" workaround for renamed / multiple foreign keys between the same pair of tables. A renamed FK is now a first-class parallel edge — no synthetic intermediate node.Why
A plain
DiGraphallows one edge per ordered node pair, so a renamed FK was split intoparent → "N" → childthrough an integer alias node, and ~14.isdigit()special-cases acrossdiagram.py(plus 5 intable.py) existed only to see through those nodes.MultiDiGraphrepresents parallel edges natively, so the whole workaround is removed — it was a historical design choice, not a NetworkX limitation.Edge identity
Each edge is keyed by the FK's child-side attribute tuple (in declaration order), e.g.
("spouse1",)vs("spouse2",). This key is:Diagram + Diagramre-adds a shared FK under the same key (overwrite, not duplicate). No defensive dedup is needed at the call sites.What changed
Dependencies/Diagramsubclassnx.MultiDiGraph;load()adds one keyed edge per FK;topo_sortdrops its alias-collapse pass;cascade()/trace()rebuild viaMultiDiGraph._find_real_edge_props→_edge_props(direct lookup).dependencies.parents()/children()return a parallel-safelist[(node, props)](was a name-keyed dict that collapsed multiple FKs from the same parent);Table.parents/children/descendants/ancestors/partsdrop the.isdigit()handling.#FF8800edge with the column renames in a hover tooltip (dot/SVG) and alinkStylerecolor (mermaid), instead of the orange alias-node dot. The orange color is layered on top of the existing line semantics — solid=primary / dashed=secondary, thick=1:1 / thin=multi are all preserved._AliasNodetier removed._apply_collapsekeeps parallel edges between two expanded tables (by key) while merging edges into a collapsed schema node to a single arrow.Verification
Full
tests/suite under the pixitestenv (MySQL 8.0 + PostgreSQL 15 via testcontainers):test_aliased_fk,test_trace_renamed_fk,test_cascade_delete_with_renamed_attrs,test_cascade_part_of_part_renamed_fk,test_upward_u3_nonprimary_master_fk; render smoke tests (test_repr_svg,test_make_image).Notes