Skip to content

fix: stop metric views re-altering on every run under view_update_via_alter - #1546

Merged
sd-db merged 4 commits into
databricks:mainfrom
sd-db:sd-db/fix/metric-view-perpetual-alter
Jun 23, 2026
Merged

fix: stop metric views re-altering on every run under view_update_via_alter#1546
sd-db merged 4 commits into
databricks:mainfrom
sd-db:sd-db/fix/metric-view-perpetual-alter

Conversation

@sd-db

@sd-db sd-db commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Description

Metric views configured with view_update_via_alter=true re-issued a redundant ALTER VIEW ... AS on every dbt run, even when the definition was unchanged.

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 on read-back — it requotes source from 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 via ALTER/replace.

Scope is specific to metric views: regular views / materialized views / streaming tables diff via QueryConfig over information_schema.views.view_definition, which for plain SQL is returned as submitted — verified that a regular view with view_update_via_alter does not perpetually diff.

Testing

  • Unit (tests/unit/relation_configs/test_metric_view_config.py): new get_diff cases for double-vs-single-quoted source and flow-vs-block lists (both failed before the fix), plus semantic-difference-detected and unparseable-fallback cases.
  • Functional (tests/functional/adapter/metric_views/test_metric_view_noop.py): a metric view with view_update_via_alter is unchanged across an identical re-run (information_schema.tables.last_altered does not advance).
  • Full tests/functional/adapter/metric_views/ suite (19) and the unit suite pass — no regressions.

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

@sd-db
sd-db requested a review from jprakash-db as a code owner June 19, 2026 08:46
@sd-db
sd-db force-pushed the sd-db/fix/metric-view-perpetual-alter branch from 0b608d4 to 6f34dee Compare June 19, 2026 08:46
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks/relation_configs
  metric_view.py
Project Total  

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
sd-db force-pushed the sd-db/fix/metric-view-perpetual-alter branch from 6f34dee to ab8c551 Compare June 19, 2026 11:17
@sd-db

sd-db commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

/integration-test

@github-actions

Copy link
Copy Markdown

Integration tests dispatched for PR #1546 by @sd-db. Track progress in the Actions tab.

@github-actions

Copy link
Copy Markdown

Integration results for PR #1546 — UC cluster ✅ success · SQL warehouse ❌ failure · All-purpose cluster ✅ success · Shard coverage ✅ success

Run details.

@sd-db

sd-db commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

Single integration test failure is for a known flaky test which can be ignored

sd-db added 2 commits June 23, 2026 12:11
…-perpetual-alter

# Conflicts:
#	CHANGELOG.md
#	tests/functional/adapter/metric_views/fixtures.py
@sd-db
sd-db merged commit d3e388b into databricks:main Jun 23, 2026
9 checks passed
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.

2 participants