Legacy semantic models pointed at their table with model: ref('orders'). In the latest YAML spec, the
one dbt v2 (the Fusion engine) expects, there is nothing to point at: the semantic model is declared inside
the model’s own YAML entry, and that entry is the reference. Adding a model: key back is the most common
mistake when converting by hand.
Copy and paste
models:
- name: orders # this is the reference
semantic_model:
enabled: true
name: orders_sm # optional: a different name for the semantic model
agg_time_dimension: order_date
columns:
- name: order_id
entity:
type: primary
name: order
- name: order_date
granularity: day
dimension:
type: time
metrics:
- name: revenue
type: simple
agg: sum
expr: amount
No model:, no ref(), no {{ }}. The semantic model reads the table that the orders model builds,
in whatever database and schema the environment puts it.
The errors when you add one
semantic_model: {enabled: true, model: ref('orders')} on dbt v2 2.0.9:
[error] [UnusedConfigKey (dbt1060)]: While parsing config: Ignored unexpected key `"model"`. YAML path:
`semantic_model.model`.
--> models/_semantic.yml:12:7
The same YAML on dbt Core 1.12:
Parsing Error
Invalid models config given in models/_semantic.yml @ models: ... - at path ['semantic_model']:
{'enabled': True, 'model': "ref('orders')"} is not valid under any of the given schemas
Delete the model: line. semantic_model: accepts enabled and an optional name.
Legacy YAML: which forms work where
If you are still on the legacy format, the model: key is required, but dbt v2 is more tolerant than dbt
1.12 about how you write it. Tested with a top-level semantic_models: block:
model: value |
dbt v2 2.0.9 | dbt Core 1.12 |
|---|---|---|
ref('orders') |
works, with the legacy YAML warning | works |
"{{ ref('orders') }}" |
works, with the legacy YAML warning | Could not render {{ ref('orders') }}: 'ref' is undefined |
orders |
works, with the legacy YAML warning | node_relation none is not an allowed value |
A project developed locally on dbt v2 with the Jinja or bare-name form can therefore fail as soon as it runs
on dbt Core 1.12, or on a dbt platform environment that still uses dbt 1.x. Use ref('orders') without
braces while you are on the legacy format, and migrate when you can.
Migrate instead of fixing by hand
dbt-autofix deprecations --semantic-layer moves each semantic model into its model entry, drops the
model: key and turns measures into simple metrics; see
how to fix the “legacy YAML” warning.
One case to keep in the legacy format for now: with dbt Mesh, a semantic model on a model from another
project (ref('other_project', 'orders')) is only supported by the legacy spec.
Tested with dbt v2 2.0.9 and dbt Core 1.12 on DuckDB.