Skip to content

Commit a1d9f28

Browse files
refactor: trim cascade diagram to seed + descendants subgraph
cascade() now removes non-descendant nodes from the returned Diagram, so the graph itself defines the delete scope. This eliminates the redundant _cascade_restrictions membership check in delete() — it simply walks all non-alias nodes in the trimmed graph. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 32597b7 commit a1d9f28

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/datajoint/diagram.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,15 @@ def cascade(self, table_expr, part_integrity="enforce"):
380380
result._restriction_attrs[node] = set(table_expr.restriction_attributes)
381381
# Propagate downstream
382382
result._propagate_restrictions(node, mode="cascade", part_integrity=part_integrity)
383+
# Trim graph to cascade subgraph: only restricted tables
384+
# (seed + descendants) plus alias nodes connecting them.
385+
keep = set(result._cascade_restrictions)
386+
for alias in (n for n in result.nodes() if n.isdigit()):
387+
if set(result.predecessors(alias)) & keep and set(result.successors(alias)) & keep:
388+
keep.add(alias)
389+
result.remove_nodes_from(set(result.nodes()) - keep)
390+
result.nodes_to_show &= keep
391+
result._expanded_nodes &= keep
383392
return result
384393

385394
def _restricted_table(self, node):
@@ -625,9 +634,9 @@ def delete(self, transaction=True, prompt=None, dry_run=False):
625634

626635
conn = self._connection
627636

628-
# Get non-alias nodes with restrictions in topological order
637+
# Get non-alias nodes in topological order (graph is already trimmed by cascade())
629638
all_sorted = topo_sort(self)
630-
tables = [t for t in all_sorted if not t.isdigit() and t in self._cascade_restrictions]
639+
tables = [t for t in all_sorted if not t.isdigit()]
631640

632641
# Preview
633642
if prompt:

0 commit comments

Comments
 (0)