Summary
Migrate Dependencies and Diagram (both currently nx.DiGraph subclasses) to
nx.MultiDiGraph, retiring the integer "alias node" workaround used to represent
multiple / renamed foreign keys between the same pair of tables.
Background
A plain nx.DiGraph permits only one edge per ordered node pair, so it cannot
represent two foreign keys between the same two tables. To work around this,
dj.Diagram inserts an integer-named alias node that splits a renamed FK into
two half-edges (parent → "N" → child), giving each FK its own edge identity
(dependencies.py:216–223).
dj.Diagram predates NetworkX's multigraph support in our design (the class dates
to ~2016). NetworkX has long shipped MultiDiGraph (parallel edges keyed by
(u, v, key)), so the alias-node workaround is no longer necessary — it is a
historical choice, not a NetworkX limitation.
Scope — what this removes
Migrating to MultiDiGraph deletes the alias machinery:
- ~14
.isdigit() special-case checks in diagram.py
_find_real_edge_props (diagram.py)
- alias-follow branches in both
_propagate_restrictions and _propagate_restrictions_upstream
- alias-node insertion at
dependencies.py:220–223
- alias-collapse in
topo_sort (dependencies.py:62–73)
Traversals we rely on (ancestors, descendants, topological_sort,
shortest_path, node_boundary) all work on multigraphs. The main change is that
edge-data access moves to (u, v, key) addressing throughout.
Diagramming notation implications
Alias nodes currently double as the visual marker for renamed FKs. Removing them
means we need new notation:
-
Renamed-FK edge notation. Design notation for a renamed foreign key as an
edge attribute (e.g. a labeled / styled / dashed edge showing child_col ← parent_col)
rather than an intermediate node.
-
Multigraph rendering support. Ensure the render backends handle parallel edges
between the same node pair:
- pydot / pygraphviz → dot / graphviz (
make_dot, make_svg, to_pydot at diagram.py:1540)
- Mermaid (
make_mermaid at diagram.py:1642)
- matplotlib
draw
Graphviz/dot support parallel edges natively; Mermaid flowcharts need multiple edge
statements between the same nodes — verify edge labels don't collide.
Risk
Broad, cross-cutting, and test-heavy: every edge-data access site plus the full
cascade / trace / restrict suites must be re-verified under multigraph edge semantics.
Not a patch-release change — hence v2.4.
References
- Surfaced during the 2.3.1
dj.Diagram review (alias-node design rationale).
- Code:
src/datajoint/dependencies.py, src/datajoint/diagram.py.
Summary
Migrate
DependenciesandDiagram(both currentlynx.DiGraphsubclasses) tonx.MultiDiGraph, retiring the integer "alias node" workaround used to representmultiple / renamed foreign keys between the same pair of tables.
Background
A plain
nx.DiGraphpermits only one edge per ordered node pair, so it cannotrepresent two foreign keys between the same two tables. To work around this,
dj.Diagraminserts an integer-named alias node that splits a renamed FK intotwo half-edges (
parent → "N" → child), giving each FK its own edge identity(
dependencies.py:216–223).dj.Diagrampredates NetworkX's multigraph support in our design (the class datesto ~2016). NetworkX has long shipped
MultiDiGraph(parallel edges keyed by(u, v, key)), so the alias-node workaround is no longer necessary — it is ahistorical choice, not a NetworkX limitation.
Scope — what this removes
Migrating to
MultiDiGraphdeletes the alias machinery:.isdigit()special-case checks indiagram.py_find_real_edge_props(diagram.py)_propagate_restrictionsand_propagate_restrictions_upstreamdependencies.py:220–223topo_sort(dependencies.py:62–73)Traversals we rely on (
ancestors,descendants,topological_sort,shortest_path,node_boundary) all work on multigraphs. The main change is thatedge-data access moves to
(u, v, key)addressing throughout.Diagramming notation implications
Alias nodes currently double as the visual marker for renamed FKs. Removing them
means we need new notation:
Renamed-FK edge notation. Design notation for a renamed foreign key as an
edge attribute (e.g. a labeled / styled / dashed edge showing
child_col ← parent_col)rather than an intermediate node.
Multigraph rendering support. Ensure the render backends handle parallel edges
between the same node pair:
make_dot,make_svg,to_pydotatdiagram.py:1540)make_mermaidatdiagram.py:1642)drawGraphviz/dot support parallel edges natively; Mermaid flowcharts need multiple edge
statements between the same nodes — verify edge labels don't collide.
Risk
Broad, cross-cutting, and test-heavy: every edge-data access site plus the full
cascade / trace / restrict suites must be re-verified under multigraph edge semantics.
Not a patch-release change — hence v2.4.
References
dj.Diagramreview (alias-node design rationale).src/datajoint/dependencies.py,src/datajoint/diagram.py.