Skip to content

Fix .transform() failing when the table is part of a view#749

Open
viraatdas wants to merge 1 commit into
simonw:mainfrom
viraatdas:libra/issues/1-transform-fails-to-drop-column-if-table-is-part
Open

Fix .transform() failing when the table is part of a view#749
viraatdas wants to merge 1 commit into
simonw:mainfrom
viraatdas:libra/issues/1-transform-fails-to-drop-column-if-table-is-part

Conversation

@viraatdas
Copy link
Copy Markdown

@viraatdas viraatdas commented Jun 2, 2026

Fixes #586.

Table.transform() raised error 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 OF triggers 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 clear TransformError naming 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.py covering: a view recreated after a transform, an INSTEAD OF trigger on a view recreated, and a view referencing an unregistered custom function (which recreates fine since CREATE VIEW is lazy). The transform test file passes (62 tests).

Prepared with AI assistance.


📚 Documentation preview 📚: https://sqlite-utils--749.org.readthedocs.build/en/749/

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.transform() fails to drop column if table is part of a view

1 participant