-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
Medium Severitybug with minor impact that does not have resolution timeframe requirementbug with minor impact that does not have resolution timeframe requirementbugSomething isn't workingSomething isn't workingunit testsIssues related to built-in dbt unit testing functionalityIssues related to built-in dbt unit testing functionality
Description
Is this a new bug in dbt-core?
- I believe this is a new bug in dbt-core
- I have searched the existing issues, and I could not find an existing issue for this bug
Current Behavior
Sometimes (but not always!), I get this compilation error when a model contains a macro:
13:04:08 Compilation Error in unit_test test__model_f (models/unit_test.yml)
'british_colours' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".
Expected Behavior
This seems like it should work without needing to add an override for any macros.
Steps To Reproduce
macros/my_macros.sql
{% macro british_colours() -%}
{{ return(["grey"]) }}
{%- endmacro %}
{% macro american_colors() -%}
{{ return(["gray"]) }}
{%- endmacro %}
models/_unit_tests.yml
unit_tests:
- name: test__model_f
model: model_f
given: []
expect:
rows:
- {id: 1}
models/model_f.sql
{% set a_values = british_colours() %}
{% set b_values = american_colors() %}
select 1 as id
Build and see that everything works just fine:
dbt build -s +model_f
Update models/model_f.sql
to add {% set ab_values = a_values + b_values %}
anywhere within the model defintion:
{% set a_values = british_colours() %}
{% set b_values = american_colors() %}
{% set ab_values = a_values + b_values %}
select 1 as id
Now re-build and see the error:
dbt build -s +model_f
13:12:43 Completed with 1 error and 0 warnings:
13:12:43
13:12:43 Compilation Error in unit_test test__model_f (models/unit_test.yml)
'british_colours' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".
Relevant log output
See above
Environment
- OS:
- Python:
- dbt:
Which database adapter are you using with dbt?
postgres
Additional Context
Found while researching #10139.
hugohjerten, dsillman2000, WobblyRobbly, codybraun, JaneJeon and 2 more
Metadata
Metadata
Assignees
Labels
Medium Severitybug with minor impact that does not have resolution timeframe requirementbug with minor impact that does not have resolution timeframe requirementbugSomething isn't workingSomething isn't workingunit testsIssues related to built-in dbt unit testing functionalityIssues related to built-in dbt unit testing functionality