Fix .transform() failing when the table is part of a view#749
Open
viraatdas wants to merge 1 commit into
Open
Conversation
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.
Fixes #586.
Table.transform()raisederror in view <name>: no such table: ...when the table was referenced by a SQL view, because the transform renames the table while a view still references it.This saves the definitions of all views (and any
INSTEAD OFtriggers on them), drops the views before the transform runs, then recreates them afterwards. If a view cannot be recreated because it referenced a column that the transform dropped or renamed, it raises a clearTransformErrornaming the view and telling the user to recreate it manually, rather than leaving the database in a broken state. It deliberately does not parse the view SQL; it relies on SQLite to report a recreate failure.Added regression tests in
tests/test_transform.pycovering: a view recreated after a transform, anINSTEAD OFtrigger on a view recreated, and a view referencing an unregistered custom function (which recreates fine sinceCREATE VIEWis lazy). The transform test file passes (62 tests).Prepared with AI assistance.
📚 Documentation preview 📚: https://sqlite-utils--749.org.readthedocs.build/en/749/