[v2 Bug] Unit test `format: sql` fixture files compile to the literal `None`
Is this a new bug in dbt v2.x compared to the latest version of dbt 1.x?
- I believe this is a new bug in dbt v2.x
- I have searched the existing issues and could not find a duplicate
Current Behavior
Under the v2 parser, a unit test given input declared as format: sql with a
fixture: file reference compiles with the fixture body replaced by the literal
string None. The fixture file is never read.
The generated CTE is therefore invalid:
with __dbt__cte__upstream_model as (
None
) select id, label from __dbt__cte__upstream_modelThe warehouse then reports the CTE as a missing object. On Snowflake:
Database Error
002003 (42S02): SQL compilation error:
Object '__DBT__CTE__UPSTREAM_MODEL' does not exist or not authorized.Two things make this hard to diagnose:
- There is no warning at parse time that the fixture file was not found. The parse succeeds and the failure surfaces only as a warehouse error at execution.
- The error names the CTE as a missing object, which points a reader at grants,
lineage, or the model's
FROMclause. The actual fault is the empty CTE body.
Expected Behavior
The fixture file's contents are inlined as the CTE body, as they are under the 1.x Python parser:
with __dbt__cte__upstream_model as (
select 1 as id, 'a' as label
) select id, label from __dbt__cte__upstream_modelFailing that, a parse-time error naming the fixture that could not be resolved,
rather than emitting None and deferring to the warehouse.
Steps To Reproduce
Minimal project. dbt_project.yml contains:
flags:
use_v2_parser: truemodels/upstream_model.sql:
select 1 as id, 'a' as labelmodels/downstream_model.sql:
select id, label from {{ ref('upstream_model') }}models/schema.yml:
version: 2
unit_tests:
- name: test_downstream_model
model: downstream_model
given:
- input: ref('upstream_model')
format: sql
fixture: upstream_rows
expect:
rows:
- {id: 1, label: a}tests/fixtures/upstream_rows.sql:
select 1 as id, 'a' as labelThen:
dbt build --select upstream_model(so the unit test has a target schema)dbt test --select test_downstream_model— fails- Inspect
target/compiled/<project>/models/schema.yml/models/test_downstream_model.sqland note the CTE body isNone - Re-run step 2 with
DBT_ENGINE_USE_V2_PARSER=0— the CTE body contains the fixture SQL and the test passes
Step 4 is the A/B: same dbt-core version, same project, same adapter, only the parser differs.
| Parser | Compiled CTE body | Result |
|---|---|---|
| v2 | None |
ERROR |
1.x Python (DBT_ENGINE_USE_V2_PARSER=0) |
the fixture SQL | PASS |
Substituting the same SQL inline resolves it, which further isolates the fault to file resolution rather than to SQL fixtures generally:
- input: ref('upstream_model')
format: sql
rows: |
select 1 as id, 'a' as labelRelevant log output
Completed with 1 error, 0 partial successes, and 0 warnings:
[ERROR]: in unit_test test_downstream_model (models/schema.yml)
Runtime Error in unit_test test_downstream_model (models/schema.yml)
An error occurred during execution of unit test 'test_downstream_model'.
There may be an error in the unit test definition: check the data types.
Database Error
002003 (42S02): SQL compilation error:
Object '__DBT__CTE__UPSTREAM_MODEL' does not exist or not authorized.
Done. PASS=0 WARN=0 ERROR=1 SKIP=0 NO-OP=0 REUSED=0 TOTAL=1Environment
- OS: macOS (Darwin 27.0.0)
- CPU: ARM
- dbt distribution and version: reproduced on two combinations
- dbt-core 1.12.4 with dbt-core-experimental-parser 2.0.0rc2
- dbt-core 1.12.5 with dbt-core-experimental-parser 2.0.4
- adapter: dbt-snowflake 1.12.0 and 1.12.1Which database adapter are you using?
snowflake
Is this a discrepancy vs. dbt 1.x?
- Yes — this works in dbt 1.x but not in dbt v2.x
Additional Context
Present in both the release candidate and the current GA parser (2.0.4), so it is not fixed by upgrading within the 2.0.x line.
One consequence worth flagging: --exclude resource_type:test does not exclude
resource_type:unit_test, so a build that deliberately skips tests still runs unit
tests. A project using SQL fixture files will therefore see a scheduled production
build fail on this, with an error that reads like a permissions problem.
I have not tested whether format: csv fixture files are affected.
Source: dbt-labs/dbt-core