fix: stop metric views re-altering on every run under view_update_via_alter - #1546
Merged
sd-db merged 4 commits intoJun 23, 2026
Merged
Conversation
sd-db
force-pushed
the
sd-db/fix/metric-view-perpetual-alter
branch
from
June 19, 2026 08:46
0b608d4 to
6f34dee
Compare
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
…_alter MetricViewQueryConfig.get_diff compared the model's compiled YAML against the server's stored View Text with a whitespace-only text comparison. Databricks re-renders the stored definition (requoting `source` double->single, rewriting flow-style lists to block style), so the comparison always reported a change and dbt re-issued `ALTER VIEW ... AS` on every run for metric views configured with view_update_via_alter. Compare the parsed YAML structurally instead, falling back to the whitespace- normalized text comparison when a definition is not valid YAML. Adds unit tests for the quote and list-style cases and a functional regression asserting an unchanged metric view is not re-altered on re-run.
sd-db
force-pushed
the
sd-db/fix/metric-view-perpetual-alter
branch
from
June 19, 2026 11:17
6f34dee to
ab8c551
Compare
Collaborator
Author
|
/integration-test |
|
Integration tests dispatched for PR #1546 by @sd-db. Track progress in the Actions tab. |
|
Integration results for PR #1546 — UC cluster ✅ success · SQL warehouse ❌ failure · All-purpose cluster ✅ success · Shard coverage ✅ success |
jprakash-db
approved these changes
Jun 22, 2026
Collaborator
Author
|
Single integration test failure is for a known flaky test which can be ignored |
…-perpetual-alter # Conflicts: # CHANGELOG.md # tests/functional/adapter/metric_views/fixtures.py
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.
Description
Metric views configured with
view_update_via_alter=truere-issued a redundantALTER VIEW ... ASon everydbt run, even when the definition was unchanged.MetricViewQueryConfig.get_diffcompared the model's compiled YAML against the server's storedView Textwith a whitespace-only text comparison. Databricks re-renders the stored definition on read-back — it requotessourcefrom double to single quotes and rewrites flow-style lists (e.g.synonyms: [a, b]) to block style — so the normalized strings never matched and dbt always saw a change.The fix compares the parsed YAML structurally (
yaml.safe_load), so quote style and flow/block list style no longer register as changes. It falls back to the previous whitespace-normalized text comparison when a definition isn't valid YAML. Genuine definition changes are still detected, so real updates still apply viaALTER/replace.Scope is specific to metric views: regular views / materialized views / streaming tables diff via
QueryConfigoverinformation_schema.views.view_definition, which for plain SQL is returned as submitted — verified that a regular view withview_update_via_alterdoes not perpetually diff.Testing
tests/unit/relation_configs/test_metric_view_config.py): newget_diffcases for double-vs-single-quotedsourceand flow-vs-block lists (both failed before the fix), plus semantic-difference-detected and unparseable-fallback cases.tests/functional/adapter/metric_views/test_metric_view_noop.py): a metric view withview_update_via_alteris unchanged across an identical re-run (information_schema.tables.last_altereddoes not advance).tests/functional/adapter/metric_views/suite (19) and the unit suite pass — no regressions.Checklist
CHANGELOG.mdand added information about my change to the "dbt-databricks next" section.