Describe the bug
The metric_view materialization renders its model body (the YAML containing comment: / display_name: fields) through the model-SQL Jinja context which does not include the doc() function. As a result, {{ doc('my_block') }} inside a metric view fails to compile:
Compilation Error in model my_metric_view
'doc' is undefined. This can happen when calling a macro that does not exist.
Every other Jinja construct works in the same metric-view body — {{ ref() }}, {{ source() }}, {{ config() }}, {{ var() }}, and custom macros all render correctly. Only doc() is missing from the context. A macro that internally calls {{ doc(name) }} fails the same way, confirming doc is simply absent from the render context (not a doc-block lookup problem).
This breaks documentation parity: for normal models, column description: fields in schema YAML support doc() (and dbt doc blocks). Metric-view comment: fields cannot, so a description maintained once as a doc block cannot be reused in a metric view — forcing duplicated, drift-prone copy.
Steps To Reproduce
-
Define a doc block:
{% docs id %}
Unique identifier of the entity.
{% enddocs %}
-
Create a metric view models/example_mv.sql:
{{ config(materialized="metric_view") }}
version: 1.1
source: {{ ref('my_fact')}}
dimensions:
- name: id
expr: id
display_name: "Entity ID"
comment: "{{ doc('enterprise_id_doc') }}" --quoted or unquoted version both fail
-
dbt parse → succeeds (does not catch the problem).
-
dbt compile --select example_mv → fails with 'doc' is undefined.
Swapping {{ doc('enterprise_id_doc') }} for {{ var('some_var') }} or a custom macro compiles and renders correctly — only doc() is unavailable.
Expected behavior
doc() should resolve inside metric_view documentation fields (comment:, display_name:) just as it does in schema-YAML description: fields, so a single doc block can document both regular-model columns and metric-view dimensions/measures, and persist_docs output stays consistent.
Screenshots and log output
�[0m10:30:09 Running with dbt=1.11.8
�[0m10:30:11 Registered adapter: databricks=1.12.0
�[0m10:30:14 Found 206 models, 832 data tests, 16 seeds, 4 snapshots, 69 sources, 1982 macros, 3 unit tests
�[0m10:30:14
�[0m10:30:14 Concurrency: 10 threads (target='playground')
�[0m10:30:14
�[0m10:30:16 1 of 1 START sql metric_view model ondra_paul.mv_ic_plus_gross_fees ............ [RUN]
�[0m10:30:16 1 of 1 ERROR creating sql metric_view model ondra_paul.mv_ic_plus_gross_fees ... [�[31mERROR�[0m in 0.02s]
�[0m10:30:16
�[0m10:30:16 Finished running 1 metric view model in 0 hours 0 minutes and 2.64 seconds (2.64s).
�[0m10:30:17
�[0m10:30:17 �[31mCompleted with 1 error, 0 partial successes, and 0 warnings:�[0m
�[0m10:30:17
�[0m10:30:17 �[31mFailure in model mv_ic_plus_gross_fees (models/metric_views/fees/mv_ic_plus_gross_fees.sql)�[0m
�[0m10:30:17 Compilation Error in model mv_ic_plus_gross_fees (models/metric_views/fees/mv_ic_plus_gross_fees.sql)
'doc' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".
�[0m10:30:17
�[0m10:30:17 Done. PASS=0 WARN=0 ERROR=1 SKIP=0 NO-OP=0 TOTAL=1
System information
The output of dbt --version:
Core:
- installed: 1.11.8
Plugins:
- databricks: 1.12.0
- spark: 1.10.1
The operating system you're using: macOS (Darwin)
The output of python --version:
Python 3.10.11
Describe the bug
The
metric_viewmaterialization renders its model body (the YAML containingcomment:/display_name:fields) through the model-SQL Jinja context which does not include thedoc()function. As a result,{{ doc('my_block') }}inside a metric view fails to compile:Every other Jinja construct works in the same metric-view body —
{{ ref() }},{{ source() }},{{ config() }},{{ var() }}, and custom macros all render correctly. Onlydoc()is missing from the context. A macro that internally calls{{ doc(name) }}fails the same way, confirmingdocis simply absent from the render context (not a doc-block lookup problem).This breaks documentation parity: for normal models, column
description:fields in schema YAML supportdoc()(and dbt doc blocks). Metric-viewcomment:fields cannot, so a description maintained once as a doc block cannot be reused in a metric view — forcing duplicated, drift-prone copy.Steps To Reproduce
Define a doc block:
Create a metric view
models/example_mv.sql:dbt parse→ succeeds (does not catch the problem).dbt compile --select example_mv→ fails with'doc' is undefined.Swapping
{{ doc('enterprise_id_doc') }}for{{ var('some_var') }}or a custom macro compiles and renders correctly — onlydoc()is unavailable.Expected behavior
doc()should resolve insidemetric_viewdocumentation fields (comment:,display_name:) just as it does in schema-YAMLdescription:fields, so a single doc block can document both regular-model columns and metric-view dimensions/measures, andpersist_docsoutput stays consistent.Screenshots and log output
System information
The output of
dbt --version:Core:
Plugins:
The operating system you're using: macOS (Darwin)
The output of
python --version:Python 3.10.11