Skip to content

Commit f4742be

Browse files
fix: use restrict_in_place for cascade restrictions in Diagram
Cascade restrictions stored as plain lists (for OR semantics) were being directly assigned to ft._restriction, causing list objects to be stringified as Python repr ("[' condition ']") in SQL WHERE clauses. Use restrict_in_place() which properly handles lists as OR conditions through the standard restrict() path. Also fix version string to be PEP 440 compliant. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8cdf42d commit f4742be

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/datajoint/diagram.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,11 @@ def _propagate_restrictions(self, start_node, mode, part_integrity="enforce"):
445445
# Build parent FreeTable with current restriction
446446
parent_ft = FreeTable(self._connection, node)
447447
restr = restrictions[node]
448-
if mode == "cascade" and restr:
449-
parent_ft._restriction = restr # plain list → OR
450-
elif mode == "restrict":
451-
parent_ft._restriction = restr # AndList → AND
452-
# else: cascade with empty list → unrestricted
448+
if restr:
449+
if mode == "cascade":
450+
parent_ft.restrict_in_place(restr) # list → OR
451+
else:
452+
parent_ft._restriction = restr # AndList → AND
453453

454454
parent_attrs = self._restriction_attrs.get(node, set())
455455

@@ -507,7 +507,7 @@ def _propagate_restrictions(self, start_node, mode, part_integrity="enforce"):
507507
child_ft = FreeTable(self._connection, target)
508508
child_restr = restrictions.get(target, [])
509509
if child_restr:
510-
child_ft._restriction = child_restr
510+
child_ft.restrict_in_place(child_restr)
511511
master_ft = FreeTable(self._connection, master_name)
512512
from .condition import make_condition
513513

@@ -625,7 +625,7 @@ def delete(self, transaction=True, prompt=None):
625625
ft = FreeTable(conn, t)
626626
restr = self._cascade_restrictions[t]
627627
if restr:
628-
ft._restriction = restr
628+
ft.restrict_in_place(restr)
629629
logger.info("{table} ({count} tuples)".format(table=t, count=len(ft)))
630630

631631
# Start transaction
@@ -649,7 +649,7 @@ def delete(self, transaction=True, prompt=None):
649649
ft = FreeTable(conn, table_name)
650650
restr = self._cascade_restrictions[table_name]
651651
if restr:
652-
ft._restriction = restr
652+
ft.restrict_in_place(restr)
653653
count = ft.delete_quick(get_count=True)
654654
logger.info("Deleting {count} rows from {table}".format(count=count, table=table_name))
655655
if table_name == tables[0]:
@@ -752,7 +752,10 @@ def preview(self):
752752
ft = FreeTable(self._connection, node)
753753
restr = restrictions[node]
754754
if restr:
755-
ft._restriction = restr
755+
if isinstance(restr, list) and not isinstance(restr, AndList):
756+
ft.restrict_in_place(restr) # cascade: list → OR
757+
else:
758+
ft._restriction = restr # restrict: AndList → AND
756759
result[node] = len(ft)
757760

758761
for t, count in result.items():

src/datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# version bump auto managed by Github Actions:
22
# label_prs.yaml(prep), release.yaml(bump), post_release.yaml(edit)
33
# manually set this version will be eventually overwritten by the above actions
4-
__version__ = "2.2.0dev0"
4+
__version__ = "2.2.0.dev0"

0 commit comments

Comments
 (0)