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
A quick thought, why not expose a dbt.var function (and similar for env var) rather than overloading config? If you apply the same limitations as for config function (ie. Only literal args) should be pretty straightforward to statically analyse which vars need to be injected?
It's true! The mechanism for dbt.var and dbt.env_var could be just the same as dbt.config.get. We detect the literal arguments passed in:
Usability and ergonomics for people developing and configuring Python models, especially ones with more advanced conditional logic or env-specific behavior
Are you interested in contributing this feature?
No response
Anything else?
To be clear, the environment variable values would need to be the ones evaluated during dbt parsing. (They are NOT the environment variables set in the runtime environment, e.g. Snowpark.)
That's slightly different from how environment variables work in SQL models today, since the {{ env_var() }} Jinja is re-rendered at compile/execute runtime.
But I think it probably should work this way across the board, where all inputs (including env vars) are resolved during parsing and pre-execution.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
[Feature] Support dbt.var + dbt.env_var in Python models
[CT-997] [Feature] Support dbt.var + dbt.env_var in Python models
Aug 5, 2022
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.
Is this your first time submitting a feature request?
Describe the feature
Copying from thread in #beta-feedback-python-models:
It's true! The mechanism for
dbt.var
anddbt.env_var
could be just the same asdbt.config.get
. We detect the literal arguments passed in:dbt-core/core/dbt/parser/models.py
Lines 113 to 117 in eb72dbf
dbt-core/core/dbt/parser/models.py
Lines 182 to 184 in eb72dbf
And then provide those values at "compile" time (which we're currently doing via Jinja... gross), as new methods (
var
+env_var
) on thedbtObj
class:dbt-core/core/dbt/include/global_project/macros/python_model/python.sql
Lines 33 to 40 in eb72dbf
dbt-core/core/dbt/include/global_project/macros/python_model/python.sql
Lines 71 to 77 in eb72dbf
Describe alternatives you've considered
Not doing this, and continuing to ask users (as we are currently) to pass those vars + env_vars in as configs in
.yml
files:Who will this benefit?
Usability and ergonomics for people developing and configuring Python models, especially ones with more advanced conditional logic or env-specific behavior
Are you interested in contributing this feature?
No response
Anything else?
To be clear, the environment variable values would need to be the ones evaluated during dbt parsing. (They are NOT the environment variables set in the runtime environment, e.g. Snowpark.)
That's slightly different from how environment variables work in SQL models today, since the
{{ env_var() }}
Jinja is re-rendered at compile/execute runtime.But I think it probably should work this way across the board, where all inputs (including env vars) are resolved during parsing and pre-execution.
The text was updated successfully, but these errors were encountered: