Skip to content

Commit 03dd0a7

Browse files
fix(#1423): gate Diagram.__getitem__ on _mode == "trace"
The trace-mode __getitem__ I added shadowed networkx.DiGraph's standard adjacency-dict lookup for ALL Diagrams, not just trace results. ERD tests (and any other code that does diagram[node_name] for adjacency) were getting DataJointError("not in this trace's subgraph") instead of the adjacency dict. Fix: short-circuit non-trace diagrams (no _mode attribute or _mode != "trace") to super().__getitem__(key) before any trace-specific logic runs. Tests: - 5 previously-failing erd tests now pass (test_erd, test_diagram_algebra, test_repr_svg, test_make_image, test_part_table_parsing). - 8/8 trace tests still pass.
1 parent 8d9d242 commit 03dd0a7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/datajoint/diagram.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ def __getitem__(self, key):
551551
Return a pre-restricted query expression (or FreeTable) for an
552552
ancestor table in this trace.
553553
554+
Only meaningful for trace diagrams (constructed via
555+
:meth:`Diagram.trace`). For ordinary diagrams, defers to
556+
:class:`networkx.DiGraph`'s adjacency-dict lookup.
557+
554558
Parameters
555559
----------
556560
key : type or str
@@ -577,6 +581,12 @@ def __getitem__(self, key):
577581
>>> trace[Session].fetch1("session_date") # class index
578582
>>> trace["my_schema.Session"].to_dicts() # string index → FreeTable
579583
"""
584+
# Non-trace diagrams: defer to networkx adjacency lookup so existing
585+
# `diagram[node_name]` patterns (used in diagram algebra, ERD tests)
586+
# keep working.
587+
if getattr(self, "_mode", None) != "trace":
588+
return super().__getitem__(key)
589+
580590
from .table import Table
581591

582592
# Resolve `key` to a full table name

0 commit comments

Comments
 (0)