Skip to content

fix: compare view body exactly instead of suffix-matching the whole definition - #803

Open
Benjamin-Knight wants to merge 1 commit into
dbt-msft:masterfrom
Benjamin-Knight:fix/view-skip-suffix-match
Open

fix: compare view body exactly instead of suffix-matching the whole definition#803
Benjamin-Knight wants to merge 1 commit into
dbt-msft:masterfrom
Benjamin-Knight:fix/view-skip-suffix-match

Conversation

@Benjamin-Knight

@Benjamin-Knight Benjamin-Knight commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Resolves #807

sqlserver__view's skip test compared the stored view definition against the model's compiled SQL with normalized_definition.endswith(normalized_sql). The stored definition is the whole statement (CREATE [OR ALTER] VIEW AS ) while the model is only the body, so any edit whose new body is a tail of the old one - most commonly deleting a leading comment or CTE - satisfied endswith() and was silently skipped. dbt run reported PASS, the change never reached the database, and --full-refresh did not fix it; once in that state every subsequent run re-confirmed the skip.

Split the header off at its separating ' AS ' (the first one - the quoted relation contains no other) and compare the remainder verbatim. Also drop the | lower and whitespace stripping: both made genuinely different bodies compare equal (where source = 'MAXIMS' vs 'maxims', or any literal containing spaces), turning a missed rebuild into a correctness bug. The comparison follows the asymmetry that a skip failing to fire costs one rebuild while a skip firing wrongly costs correctness - an unparseable definition (no ' AS ') rebuilds rather than guessing.

Also removes the dead normalized_relation local, which was computed but never read.

Add regression tests: removing a leading comment now lands in the stored definition, and a change confined to the case of a string literal rebuilds.

…efinition

sqlserver__view's skip test compared the stored view definition against the
model's compiled SQL with normalized_definition.endswith(normalized_sql). The
stored definition is the whole statement (CREATE [OR ALTER] VIEW <name> AS
<body>) while the model is only the body, so any edit whose new body is a tail
of the old one - most commonly deleting a leading comment or CTE - satisfied
endswith() and was silently skipped. dbt run reported PASS, the change never
reached the database, and --full-refresh did not fix it; once in that state
every subsequent run re-confirmed the skip.

Split the header off at its separating ' AS ' (the first one - the quoted
relation contains no other) and compare the remainder verbatim. Also drop the
| lower and whitespace stripping: both made genuinely different bodies compare
equal (where source = 'MAXIMS' vs 'maxims', or any literal containing spaces),
turning a missed rebuild into a correctness bug. The comparison follows the
asymmetry that a skip failing to fire costs one rebuild while a skip firing
wrongly costs correctness - an unparseable definition (no ' AS ') rebuilds
rather than guessing.

Also removes the dead normalized_relation local, which was computed but never
read.

Add regression tests: removing a leading comment now lands in the stored
definition, and a change confined to the case of a string literal rebuilds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

View changes silently not applied when the new body is a tail of the old one

1 participant