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 fails when macro is used with jinja filter #10410

Open
2 tasks done
matthewchoy-envisso opened this issue Jul 5, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working triage unit tests Issues related to built-in dbt unit testing functionality

Comments

@matthewchoy-envisso
Copy link

matthewchoy-envisso commented Jul 5, 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

When calling calling a macro passed to a jinja filter, the unit tests will fail, while the model can be compiled and run correctly.
Removing the jinja filter fixes the issue.
Creating a new macro to apply the jinja filter also works.

Expected Behavior

Using a macro with a jinja filter would not cause the unit test to fail.

Steps To Reproduce

my_macro.sql

{%- macro my_macro() -%}
    column_a
{%- endmacro -%}

my_model.sql

select {{ my_macro() | indent(4) }}

unit_test.sql

A unit test...
  • Compiling the model will succeed.
  • Running the model will succeed.
  • Running the unit test will fail.
  • Building the model will fail.

Error message:

Compilation Error in unit_test my_unit_test (<path>)
  'my_macro' 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

No response

Environment

No response

Which database adapter are you using with dbt?

No response

Additional Context

Work around:

Wrap the jinja filter in another macro.

indent.sql

{%- macro indent(text, width) -%}
    {{ text|indent(width=width)}}
{%- endmacro -%}

Then update my_model.sql

select {{ indent(my_macro(), 4) }}
@matthewchoy-envisso matthewchoy-envisso added bug Something isn't working triage labels Jul 5, 2024
@dbeatty10 dbeatty10 added the unit tests Issues related to built-in dbt unit testing functionality label Jul 8, 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 triage unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

No branches or pull requests

2 participants