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
$ dbt --debug run | grep -E 'select 1|select 2'
select 1 as id -- analytics.my_sources.my_source
select 2 -- update development.dbt_jyeo.foo set foo = 'bar'
Clearly {{ source('my_sources', 'my_source') }} evaluated correctly when it's in the body of the model but when we declare it in a set and then assign that to a hook, it becomes weird (evaluates to the {{ this }} for some reason).
Relevant log output
No response
Environment
- OS: macOS
- Python: 3.8.7
- dbt: 1.2.1
Which database adapter are you using with dbt?
snowflake
Additional Context
I know this is not best practice but more so for understanding why this is happening.
For readers, to make this work properly, we could do something like:
github-actionsbot
changed the title
[Bug] Source not evaluated properly when used in a set block which is then assigned to a hook in a model file
[CT-1341] [Bug] Source not evaluated properly when used in a set block which is then assigned to a hook in a model file
Oct 13, 2022
Thanks @jeremyyeo. I believe this is the same issue as #4606 (and #2793 before that).
In its first parse through the project, dbt captures all refs (to construct the DAG) but renders the code with a "dummy" value. That "dummy" value is, for no great reason, the current node reference.
Put another way: At parse time, we don't have the resolved form of that source yet. So {{ this }} is the placeholder used instead.
This is a problem that crops up with some frequency, so it is worth figuring out what an actually good solution might be. Best I've come up with is finding a way to store the raw/unrendered values of all configs (especially hooks) at parse time—not a thing we can do today—and then re-rendering them at execution time. It's not a totally satisfying answer.
Closing this for now as a duplicate, but it shouldn't be far from our thoughts.
Is this a new bug in dbt-core?
Current Behavior
It looks like source doesn't work properly when it's being used in a
set
jinja block + used in a hook.Expected Behavior
source()
should always evaluate correctly everywhere no matter where we're calling it.Steps To Reproduce
dbt_project.yml
- nothing special.Clearly
{{ source('my_sources', 'my_source') }}
evaluated correctly when it's in the body of the model but when we declare it in aset
and then assign that to a hook, it becomes weird (evaluates to the{{ this }}
for some reason).Relevant log output
No response
Environment
Which database adapter are you using with dbt?
snowflake
Additional Context
I know this is not best practice but more so for understanding why this is happening.
For readers, to make this work properly, we could do something like:
The text was updated successfully, but these errors were encountered: