You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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).
Activity
refactor(graph): migrate Dependencies & Diagram to nx.MultiDiGraph (#…
refactor(graph): migrate Dependencies & Diagram to nx.MultiDiGraph (#…
refactor(graph): migrate Dependencies & Diagram to nx.MultiDiGraph (#…
test: cover parallel foreign-key edges to the same parent (#1492) (#1514