Skip to content

fix(diagram): copy a restriction to a related table only when its attributes are known exactly - #1758

Open
dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/cascade-copy-exact
Open

dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/cascade-copy-exact

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Fixes #1757.

Summary

Diagram.cascade, Diagram.restrict and Diagram.trace copy a restriction to a related table when its attributes lie within the foreign key. A string condition's attributes are parsed from its SQL text, so they may be incomplete. With this change, a restriction that contains a string condition anywhere propagates through the related rows instead of being copied.

  • condition.py: make_condition marks a restriction's attribute set as inexact whenever a string condition contributes to it, including strings nested in AND, OR and NOT lists.
  • expression.py: each query carries that mark (private _restriction_attributes_exact).
  • diagram.py: each diagram records which nodes' restrictions are inexact. The copy rule, downward and upward, applies only to exact ones, and everything else uses the projection rule. A seed replaced by its keys (dj.Top, or a restriction by another query) is exact.

Behavior:

  • Dict, key and query restrictions are copied as before, so self.upstream is unchanged.
  • String restrictions now use an IN (SELECT …) subquery where they used a copied condition. Rows are selected exactly through the referenced rows.
  • trace from a string seed now selects only the parents that the seed rows reference.

No public API is added. extract_column_names and the generated SQL for each condition are unchanged.

Tests

New integration tests in test_cascade_overdelete.py, on MySQL and PostgreSQL, using two string forms the parser reads incompletely:

  • cascade: counts and delete;
  • restrict;
  • trace;
  • part_integrity="cascade";
  • a dict restriction, which is still copied.

The 12 string-form tests fail without the change. The full suite passes: 2071 passed, 17 skipped.

…ributes are known exactly

Cascade, restrict and trace copy a restriction from one table to the next
when its attributes lie within the foreign key. The attributes of a string
condition are parsed from its SQL text, so they are not known exactly.
A restriction with a string condition anywhere in it now propagates
through the related rows (the projection rule) instead of being copied.
Dict, key and query restrictions, and restrictions produced by
propagation, are copied as before.
@dimitri-yatsenko dimitri-yatsenko added this to the v2.3.7 milestone Nov 25, 2026
@dimitri-yatsenko dimitri-yatsenko added the bug Indicates an unexpected problem or unintended behavior label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagram traversal copies a string restriction whose attributes are parsed, not known

1 participant