Skip to content

fix: auto-quote backtick-rendered refs in metric_view YAML body (#1361)#1430

Open
sd-db wants to merge 2 commits into1.12.latestfrom
sd-db/fix/1361-metric-view-yaml-auto-quote
Open

fix: auto-quote backtick-rendered refs in metric_view YAML body (#1361)#1430
sd-db wants to merge 2 commits into1.12.latestfrom
sd-db/fix/1361-metric-view-yaml-auto-quote

Conversation

@sd-db
Copy link
Copy Markdown
Collaborator

@sd-db sd-db commented Apr 28, 2026

Closes #1361.

Bug

Bare {{ ref('x') }} in a metric_view source: field renders to `db`.`schema`.`x`, which the YAML scanner rejects:

[METRIC_VIEW_INVALID_VIEW_DEFINITION] Failed to parse YAML:
found character '`' that cannot start any token

Fix

Add SqlUtils.yaml_quote_backtick_values — wraps backtick-rendered identifiers in mapping values with "..." before the body is embedded in $$..$$. Preserves SQL identifier escaping for non-trivial names (hyphens, reserved words). Called from the metric_view create and alter macros.

Same shape as SqlUtils.clean_sql and the STREAM strip in streaming_table/create.sql.

Test plan

  • Unit: 10 parametrized cases (tests/unit/test_handle.py) — idempotence, multi-line, indented, inline backticks left alone, etc.
  • Functional: TestMetricViewBareRef runs a bare-ref metric_view + round-trips a MEASURE() query
  • Full tests/functional/adapter/metric_views/ suite (18 tests) — no regressions
  • pre-commit run --all-files clean

Bare `{{ ref(...) }}` in a metric_view source: line rendered to
`db`.`schema`.`name` and broke the YAML scanner with
METRIC_VIEW_INVALID_VIEW_DEFINITION. Wrap such values in YAML double
quotes before embedding the body, preserving SQL identifier escaping.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks
  handle.py
  impl.py 974, 978
Project Total  

This report was generated by python-coverage-comment-action

@sd-db sd-db self-assigned this Apr 28, 2026
@sd-db
Copy link
Copy Markdown
Collaborator Author

sd-db commented Apr 28, 2026

/integration-test

@github-actions
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown

Integration results for PR #1430 — UC cluster ✅ success · SQL warehouse ✅ success · All-purpose cluster ✅ success

Run details.

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.

1 participant