-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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] Pre- and post-hooks use parse phase values during the execution phase #10148
Comments
Thanks for reaching out about this and providing such a nice example @Klimmy 🤩 This is expected, and you're not the first to be surprised. See #6837 (comment) and other linked issues for explanations. ExampleTry out the following to see how you can still get the behavior you are after.
{# jinja for parsing phase #}
{% if execute %}
{% set val = 111 %}
{% else %}
{% set val = 999 %}
{% endif %}
{# jinja for execution phase #}
{% set jinja_for_execution = """
{% if execute %}
{% set val = 111 %}
{% else %}
{% set val = 999 %}
{% endif %}
""" %}
{{
config(
pre_hook=[
jinja_for_execution ~ "{{ print('❌ Pre-hook X. Execute: " ~ execute ~ "; Value: " ~ val ~ "') }}",
jinja_for_execution ~ "{{ print('✅ Pre-hook Y. Execute: ' ~ execute ~ '; Value: ' ~ val ~ '') }}",
jinja_for_execution ~ "SELECT {{ val }} AS pre_hook_sql",
],
)
}}
SELECT 1 AS id dbt --no-partial-parse run -s my_model Output:
Since this is expected behavior rather than a bug, I'm going to close this issue as not planned. But just let me know if you have any follow-up thoughts or questions. |
Wow, thank you, @dbeatty10, for such a quick and detailed response! |
No need to apologize -- glad to connect you with helpful information. |
Is this a new bug in dbt-core?
Current Behavior
I'm unsure if that's expected, but when I run pre/post-hook with a variable, dbt compiles the hook statement using variable value from the parse phase.
In the following example, the pre-hook will be
SELECT 999
instead ofSELECT 111
:Expected Behavior
To have execution-phase values when the hook runs.
Steps To Reproduce
hook_issue.sql
dbt --no-partial-parse run --select models/hook_issue.sql
Relevant log output
Environment
Which database adapter are you using with dbt?
postgres
Additional Context
No response
The text was updated successfully, but these errors were encountered: