Repository navigation
fix(cascade): restrict only the rows a cascade reaches - #1592
Open
dimitri-yatsenko wants to merge 1 commit into
Open
dimitri-yatsenko wants to merge 1 commit into
dimitri-yatsenko wants to merge 1 commit into
Conversation
Three cases deleted rows outside the cascade: - `(T & dj.Top(n)).delete()` and `delete_quick()` ignored the Top and deleted every row matching the other conditions. A Top seed is now replaced by the primary keys it selects. - A parent restriction was copied to a child whenever the restricted attributes were in the child's primary key. Through a nullable foreign key that shares a primary-key column, the copy also deleted child rows whose foreign key is NULL; in a diamond it missed rows. The copy now applies only when the restricted attributes are among the foreign key's attributes and the foreign key lies in the child's primary key. Otherwise the child is restricted by the projected parent. - With part_integrity="cascade", the part-to-master lift copied the part's condition to the master, which also deleted masters with no matching part rows. The master is now restricted by the restricted part, so a master joins the cascade only if one of its part rows did. The walk's restrictions on intermediate parts are restored once the master is materialized; the master cascades back to all of its parts. The Diagram copy constructor now copies each node's restriction list instead of deep-copying projected query expressions, which hold a live connection.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1589, closes #1590, closes #1591.
A cascade delete reached rows outside the cascade in three cases:
dj.Topseed (delete()ignores adj.Toprestriction and deletes every matching row #1589).Diagram.cascadeandDiagram.tracebuilt the seed from the WHERE restriction only, anddelete_quickusedwhere_clause()only. A seed restricted byTopis now replaced by the primary keys it selects.part_integrity="cascade"deletes masters that have no matching part rows #1591). Withpart_integrity="cascade", the lift copied the part's condition to the master, which selected masters with no matching part rows. The master is now restricted by the restricted part, so a master joins the cascade only if one of its part rows did.Two follow-on changes:
Diagramcopy constructor copies each node's restriction list instead of deep-copying it. Projected restrictions are query expressions bound to a live connection and cannot be deep-copied. This affectedprune()and the diagram operators afterrestrict().Not changed:
Diagram.tracekeeps its upward copy for now.self.upstreamtraces from a row thatmake()has not inserted yet and relies on it. The traversal redesign for 2.4 defines that case explicitly.Tests:
tests/integration/test_cascade_overdelete.pyadds four tests on MySQL and PostgreSQL. All fail on v2.3.4 and pass here. The full suite passes locally (1166 passed, 14 skipped).The same commit is cherry-picked onto
maint/2.3for a v2.3.5 patch release.