Transform now refuses to run inside a transaction if destructive foreign keys exist#795
Merged
Merged
Conversation
…ign keys exist PRAGMA foreign_keys cannot be changed inside a transaction, and the defer_foreign_keys fallback only defers violation checks, not ON DELETE actions - so calling table.transform() inside db.atomic() with PRAGMA foreign_keys enabled would silently fire ON DELETE CASCADE / SET NULL / SET DEFAULT actions on referencing tables when the old table is dropped. transform() now raises TransactionError in that situation, naming the offending foreign keys and suggesting either running it outside the transaction or turning the pragma off before opening it. Tables with only non-destructive inbound foreign keys (NO ACTION, RESTRICT) can still be transformed inside a transaction via defer_foreign_keys. Closes #794 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014StVTWQJpFhfZJK2CYVBwv
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #795 +/- ##
=======================================
Coverage 95.55% 95.55%
=======================================
Files 9 9
Lines 3798 3802 +4
=======================================
+ Hits 3629 3633 +4
Misses 169 169 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
simonw
commented
Jul 12, 2026
|
|
||
| .. _python_api_transform_foreign_keys_transactions: | ||
|
|
||
| Foreign keys and transactions |
Owner
Author
There was a problem hiding this comment.
Move the Foreign keys and transactions section to the bottom of the transform section, not the top where it is right now
Owner
Author
|
New documentation section: https://sqlite-utils--795.org.readthedocs.build/en/795/python-api.html#foreign-keys-and-transactions |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014StVTWQJpFhfZJK2CYVBwv
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.
Refs:
Claude-Session: https://claude.ai/code/session_014StVTWQJpFhfZJK2CYVBwv
📚 Documentation preview 📚: https://sqlite-utils--795.org.readthedocs.build/en/795/