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 test raising error '<macro name>' is undefined. This can happen when calling a macro that does not exist. #10157

Open
2 tasks done
dbeatty10 opened this issue May 16, 2024 · 0 comments
Labels
bug Something isn't working Medium Severity bug with minor impact that does not have resolution timeframe requirement unit tests Issues related to built-in dbt unit testing functionality

Comments

@dbeatty10
Copy link
Contributor

dbeatty10 commented May 16, 2024

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.

@dbeatty10 dbeatty10 added bug Something isn't working triage unit tests Issues related to built-in dbt unit testing functionality and removed triage labels May 16, 2024
@graciegoheen graciegoheen added the Medium Severity bug with minor impact that does not have resolution timeframe requirement label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Medium Severity bug with minor impact that does not have resolution timeframe requirement unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

No branches or pull requests

2 participants