Skip to content
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 tests cannot be run if config block includes a call to var() #11204

Closed
2 tasks done
AndresVelasco opened this issue Jan 9, 2025 · 4 comments
Closed
2 tasks done
Labels
bug Something isn't working duplicate This issue or pull request already exists unit tests Issues related to built-in dbt unit testing functionality

Comments

@AndresVelasco
Copy link

AndresVelasco commented Jan 9, 2025

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

If the model's config block includes a call to var() as we do in our case to optionally prefix the output schema, unit test always fail with message:
'var' is undefined. This can happen when calling a macro that does not exist.

Also when I tried to define var in unit test overrides

Expected Behavior

Unit test should run normally

Steps To Reproduce

model:

{{ config(materialized='table', schema=var('x', default='')+"DUMMY") }}

select 1 as dummy

yml (unit tests):

unit_tests:
  - name: dummy_test
    model: dummy
    given:
      - input: ref('a')
        format: sql
        rows: |
          SELECT 'a' AS id
    expect:
      format: sql
      rows: |
          SELECT 1 AS dummy

Relevant log output

dbt test --select test_type:unit:


16:48:25  Running with dbt=1.9.1
16:48:26  Registered adapter: bigquery=1.9.0
16:48:26  Unable to do partial parsing because saved manifest not found. Starting full parse.
16:48:29  Found 3 models, 4 data tests, 489 macros, 1 unit test
16:48:29  
16:48:29  Concurrency: 1 threads (target='dev')
16:48:29  
16:48:32  1 of 1 START unit_test dummy::dummy_test ....................................... [RUN]
16:48:32  1 of 1 ERROR dummy::dummy_test ................................................. [ERROR in 0.02s]
16:48:32  
16:48:32  Finished running 1 unit test in 0 hours 0 minutes and 2.89 seconds (2.89s).
16:48:33  
16:48:33  Completed with 1 error, 0 partial successes, and 0 warnings:
16:48:33  
16:48:33    Compilation Error in unit_test dummy_test (models/dummy.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".
16:48:33  
16:48:33  Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1

Environment

- OS: ubuntu 20.04
- Python: 3.10
- dbt: 1.9.1

Which database adapter are you using with dbt?

bigquery

Additional Context

full test project for reproducing
dbt_test.tar.gz

@AndresVelasco AndresVelasco added bug Something isn't working triage labels Jan 9, 2025
@dbeatty10 dbeatty10 added the unit tests Issues related to built-in dbt unit testing functionality label Jan 10, 2025
@dbeatty10
Copy link
Contributor

Thanks for reaching out @AndresVelasco !

This looks the same as #10353, so I'm going to close this as a duplicate.

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
@dbeatty10 dbeatty10 added duplicate This issue or pull request already exists and removed triage labels Jan 10, 2025
@AndresVelasco
Copy link
Author

This looks like a simple issue @dbeatty10
is its resolution in roadmap already?

@dbeatty10
Copy link
Contributor

@AndresVelasco things can sometimes be much harder than they appear. There's the beginnings of a fix in #10849, and it will take quite a bit more time investment to determine a fix that can be merged. So we don't have estimated time to resolution.

@AndresVelasco
Copy link
Author

I understand! thanks for letting me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

No branches or pull requests

2 participants