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

Calls to config(vars=...) should update the local context's var(...) function #1149

Closed
beckjake opened this issue Nov 23, 2018 · 1 comment
Closed

Comments

@beckjake
Copy link
Contributor

beckjake commented Nov 23, 2018

Feature

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.

@drewbanin
Copy link
Contributor

closing - vars are project-scoped as of 0.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants