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 · 2 comments · May be fixed by #10849
Open
2 tasks done

[Bug] Unit Test fails when macro is used with jinja filter #10410

matthewchoy-envisso opened this issue Jul 5, 2024 · 2 comments · May be fixed by #10849
Labels
bug Something isn't working 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
@DanMawdsleyBA
Copy link

I'm facing a similar issue whenever I try to run a dbt model that refers to another macro. The model can build correctly however the unit test would always fail. If I remove the macro then the unit test works.

@dbeatty10
Copy link
Contributor

Thanks for reporting this @matthewchoy-envisso !

This error message looks similar to #10353, so I suspect they may have the same underlying root cause(s).

@dbeatty10 dbeatty10 removed the triage label Jul 19, 2024
@devmessias devmessias linked a pull request Oct 14, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants