The problem I’m having
I have a model that uses a a project level variable to set a variable value in the model. When I compile, all is well. When I run dbt test
(which includes unit tests) I get an error that. the var value is not recognized.
in dbt_project.yml
vars:
min_speed: 5
at the top of my model file, I have. Basically setting a number of hours (at the minimum speed) to get to a total value of 50.
{% set hours_to_look_ahead_ceil = ((50 / var('min_speed') | round(method='ceil')) | int) %}
When I run dbt test --select model
I get the following error:
Finished running 1 unit test in 0 hours 0 minutes and 2.61 seconds (2.61s).
14:22:17
14:22:17 Completed with 1 error and 0 warnings:
14:22:17
14:22:17 Compilation Error in unit_test test_mrt__[[model name]] (models/_properties.yml)
'var' is undefined. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".
14:22:17
14:22:17 Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1
The context of why I’m trying to do this
We have project level decisions set at project variables. I am honoring this hierarchy in my work.
What I’ve already tried
I attempted to move the variable setting lower int he model script. I also attempted to create a macro that sets this value - however then I ran into a different issue (I use this variable as the max in a for loop range
{%- for n in range(1, hours_to_look_ahead_ceil ) %}
[[some code ]]
{% endfor %}
And this does not want to accept a macro call as an input.
Some example code or error messages
included above.