fix(view): sp_refreshview when a view rebuild is skipped - #821
Merged
axellpadilla merged 2 commits intoAug 19, 2026
Conversation
A skipped view rebuild (unchanged compiled SQL) left select * views serving stale, shifted columns whenever a referenced table's shape changed, since SQL Server caches select * expansion at CREATE/ALTER time and the skip never reissues that statement. Run sp_refreshview on the skip path instead of a no-op so the cached column metadata stays in sync without forcing a real rebuild. Verified by executing the generated declare/exec statement directly against a live warehouse view.
The unchanged-view no-op test asserted sys.objects.modify_date was unchanged across a rerun. That was a valid stand-in for "no rebuild" only while the skip path emitted a literal no-op; sp_refreshview bumps modify_date exactly as an ALTER does, so the assertion now fails on a correctly skipped run. Assert what the test was written to guard instead: the run emits sp_refreshview, emits no CREATE OR ALTER VIEW, and leaves the stored definition byte-identical. Add the coverage the refresh itself was missing: a view selecting * from a table created outside dbt, whose shape then changes, must report the table's current columns after a run that skipped the CREATE. Also give the refresh statement the model's database as a USE prefix. sp_refreshview resolves its argument in the current database, so a cross-database view model would have errored on an unresolvable name where it previously executed a harmless no-op.
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.
resolves #820
A skipped view rebuild (unchanged compiled SQL) left select * views serving stale, shifted columns whenever a referenced table's shape changed, since SQL Server caches select * expansion at CREATE/ALTER time and the skip never reissues that statement. Run sp_refreshview on the skip path instead of a no-op so the cached column metadata stays in sync without forcing a real rebuild.