You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a macro that parses a SQL query in a post-hook for a model. In that query there is both a reference to {{this}} -- the model calling the post-hook, and {{ref('other_model)}} -- another dbt model. When executed, the built query, where what should be the table path of {{ref('other_model')}}, instead has the table path of the model invoking the post-hook {{this}}
see screenshot for clarity
Steps To Reproduce
create a model my_model
create a second model other_model
create a macro and call it as a post-hook in my_model {{config(...post_hook=[...])}}
observe in Snowflake query history that when parsed, the query fired by the post-hook, instead of what should be the table path of {{ref('other_model'), is instead the table path of {{this}}
see screenshot for clarity
Expected behavior
I expect {{ref('other_model')}} to parse to the proper table name of that model.
The operating system you're using:
OSX 11.6 The output of python --version:
Python 3.8.8
Additional context
When trying to debug this I logged the built query in the last line of my macro using {{log(my_query_var,info=true}}), which would result in output to console twice: once during the compile stage (shortly after beginning dbt run), and a second time at the execution stage right after the model completes materialization and the post-hook is fired.
What I noticed is that the query string is incorrect when it is first logged at compile time, however it is correct when it is logged right as the post-hook is fired. However, the query actually showing up in Snowflake query history (the one actually sent by DBT) is the incorrect first one generated during the compile stage.
Possibly related to Issue #3985 I just opened as well
The text was updated successfully, but these errors were encountered:
@danny-dailypay This is indeed the same issue as the one you observed in #3985. Nice work, too, on logging my_query_var and seeing that it yields different values at parse vs. execute time—you're right on the money.
At parse time, when dbt is rendering and storing node configs, it renders ref() inside post hooks with a placeholder value (i.e. the current model). In order to correctly re-render that ref() at execution time, and have that be the query that dbt actually runs against Snowflake, you need to wrap the macro call in your hook within an extra set of quotes and curlies:
This is far from lovely syntax, but it should offer a functional workaround for the thing you're after here. I think a longer-term solution may be to re-render all hooks at execution time—though that will require a mechanism to store their un-rendered config at parse time, something that dbt isn't quite yet capable of doing (#3680).
Describe the bug
I have a macro that parses a SQL query in a post-hook for a model. In that query there is both a reference to
{{this}}
-- the model calling the post-hook, and{{ref('other_model)}}
-- another dbt model. When executed, the built query, where what should be the table path of{{ref('other_model')}}
, instead has the table path of the model invoking the post-hook{{this}}
see screenshot for clarity
Steps To Reproduce
my_model
other_model
my_model {{config(...post_hook=[...])}}
{{ref('other_model')
, is instead the table path of{{this}}
see screenshot for clarity
Expected behavior
I expect
{{ref('other_model')}}
to parse to the proper table name of that model.Screenshots and log output
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
OSX 11.6
The output of
python --version
:Python 3.8.8
Additional context
When trying to debug this I logged the built query in the last line of my macro using
{{log(my_query_var,info=true}})
, which would result in output to console twice: once during the compile stage (shortly after beginning dbt run), and a second time at the execution stage right after the model completes materialization and the post-hook is fired.What I noticed is that the query string is incorrect when it is first logged at compile time, however it is correct when it is logged right as the post-hook is fired. However, the query actually showing up in Snowflake query history (the one actually sent by DBT) is the incorrect first one generated during the compile stage.
Possibly related to Issue #3985 I just opened as well
The text was updated successfully, but these errors were encountered: