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] Unable to use macros in schema.yml pre/post-hook #9482

Closed
2 tasks done
jtmcn opened this issue Jan 29, 2024 · 1 comment
Closed
2 tasks done

[Bug] Unable to use macros in schema.yml pre/post-hook #9482

jtmcn opened this issue Jan 29, 2024 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@jtmcn
Copy link

jtmcn commented Jan 29, 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 a macro is added to a pre-hook or post in a model config block in yaml, it results in a Compilation Error.

Expected Behavior

The macro should not be rendered when the yaml is parsed, causing an error. It should be rendered at run time.

Steps To Reproduce

  1. Create and define some_macro.sql
  2. Add to model config:
- name: model_name
  config:
    +pre-hook: "{{ some_macro() }}"
  1. dbt compile

Relevant log output

Compilation Error
  Could not render {{ some_macro() }}: 'some_macro' is undefined

Environment

- OS: macOS
- Python: 3.10.13
- dbt: 1.7.6

Which database adapter are you using with dbt?

snowflake

Additional Context

Previously existing, but closed bug 7128

In a potentially related bug 6425 @jtcohen6 refers to renderer.py where the should_render_keypath function was looking for post-hook rather than post_hook. I see that both are now accepted in the late_rendered_hooks. However, in my debugging it looks like the keypath is empty and thus returns True before reaching that if statement

@jtmcn jtmcn added bug Something isn't working triage labels Jan 29, 2024
@dbeatty10
Copy link
Contributor

Thanks for doing that research and raising this issue @jtmcn !

#6411 looks like something different to me. But #7128 looks like exactly the same thing, so I'm going close this issue in favor of re-opening it.

In the meantime, here's something that should work for you -- add your pre hook to your model's config block instead:

{{ config(
    pre_hook="{{ some_macro() }}"
) }}

...

Let me know if that doesn't work for some reason!

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
@dbeatty10 dbeatty10 removed the triage label Jan 30, 2024
@dbeatty10 dbeatty10 added the duplicate This issue or pull request already exists label Jul 21, 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 duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants