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
Calls to config() with a vars parameter should update the vars in a way that's accessible to the current model
Feature description
Currently in dbt, if you have a config() call in your model that adds vars, those vars aren't available to the model.
Currently, this model will fail at compile time if nothing else has set 'a':
{{
config(
vars={'a': 1}
)
}}
select {{ var('a') }} as id
with this error:
Compilation Error in model x (models/x.sql)
Required var 'a' not found in config:
Vars supplied to x = {}
I definitely did not expect that! config() calls should be able to set vars in a way that's visible to the parser.
Design
The looks a bit involved due to the parser's structure: Currently Var takes the context as an argument but only uses it for rendering, but the config() call updates its SourceConfig only and avoids touching the model. We probably have to give Var access to the SourceConfig and use that for lookups instead of just the model, and update Var's picture of model configs whenever the SourceConfig is updated (maybe defer the merge() call until runtime?). This is further complicated by the fact that var is inserted into the context after most other things, which adds another level of complexity to the problem.
We've discussed that context/SourceConfig/Var/Model config probably merits a fresh look given its age and the fact that we've learned so much about how dbt should operate since they were written. Currently they're a bit tangled up and maybe this issue is a good opportunity to give the construct a fresh look.
This is kind of related to #588 - I found this behavior while writing a test for it.
Who will this benefit?
Users of dbt.
The text was updated successfully, but these errors were encountered:
Feature
Calls to
config()
with avars
parameter should update the vars in a way that's accessible to the current modelFeature description
Currently in dbt, if you have a
config()
call in your model that adds vars, those vars aren't available to the model.Currently, this model will fail at compile time if nothing else has set 'a':
with this error:
I definitely did not expect that!
config()
calls should be able to set vars in a way that's visible to the parser.Design
The looks a bit involved due to the parser's structure: Currently
Var
takes the context as an argument but only uses it for rendering, but theconfig()
call updates itsSourceConfig
only and avoids touching the model. We probably have to giveVar
access to theSourceConfig
and use that for lookups instead of just the model, and updateVar
's picture of model configs whenever theSourceConfig
is updated (maybe defer themerge()
call until runtime?). This is further complicated by the fact thatvar
is inserted into the context after most other things, which adds another level of complexity to the problem.We've discussed that context/
SourceConfig
/Var
/Model config probably merits a fresh look given its age and the fact that we've learned so much about how dbt should operate since they were written. Currently they're a bit tangled up and maybe this issue is a good opportunity to give the construct a fresh look.This is kind of related to #588 - I found this behavior while writing a test for it.
Who will this benefit?
Users of dbt.
The text was updated successfully, but these errors were encountered: