-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Unit test compilation error 'var is undefined' when combining a variable with math operators #10353
Comments
I can also add that it doesn't work even if you add this variable to overrides->vars |
Thanks for reporting this @adamribaudo-velir and @dkultasev for confirming. I also observed the same thing. Simplified reprex below.
version: 2
unit_tests:
- name: test_unit_test
model: test
given: []
expect:
format: csv
rows: |
result
10 This worked for select {{ var('foo', 10) }} as result But it didn't when I changed it to this: select {{ var('foo', 10) * 1 }} as result $ dbt build -s test
00:11:04 Running with dbt=1.8.3
00:11:04 Registered adapter: duckdb=1.8.1
00:11:05 Found 1 model, 406 macros, 1 unit test
00:11:05
00:11:05 Concurrency: 1 threads (target='dev')
00:11:05
00:11:05 1 of 2 START unit_test test::test_unit_test .................................... [RUN]
00:11:05 1 of 2 ERROR test::test_unit_test .............................................. [ERROR in 0.01s]
00:11:05 2 of 2 SKIP relation feature_456.test .......................................... [SKIP]
00:11:05
00:11:05 Finished running 1 unit test, 1 view model in 0 hours 0 minutes and 0.19 seconds (0.19s).
00:11:05
00:11:05 Completed with 1 error and 0 warnings:
00:11:05
00:11:05 Compilation Error in unit_test test_unit_test (models/_unit_tests.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".
00:11:05
00:11:05 Done. PASS=0 WARN=0 ERROR=1 SKIP=1 TOTAL=2 |
This error message looks similar to #10410, so I suspect they may have the same underlying root cause(s). |
To perhaps help narrow down the problem: We ran into the same problem with
would run into the error while
would not. Interestingly, replacing the plus with the Jinja string concatenation operator also avoided this problem:
|
I found that var('foo', 10 ) * 1} dosen't work but var('foo', 10 ) works because the template is rendered with no var object specified. So var("foo", 10) will not be rendered you will get |
Is this a new bug in dbt-core?
Current Behavior
When running a unit test for a model that contains a Jinja math operation on a variable, a compilation error occurs
Example operation
Error:
Running the unit test on a Jinja variable without the math operation works successfully. Ex:
select {{ var('foo', 10 ) }} as result
Expected Behavior
Expected behavior would be to compile unit test and executing the math operation on the variable.
Steps To Reproduce
test
with the following SQL:dbt test -s test_unit_test
Relevant log output
Environment
Which database adapter are you using with dbt?
bigquery
Additional Context
No response
The text was updated successfully, but these errors were encountered: