-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Spike+][jinja if statement] [false positives] environment-aware logic in config should not cause resources to always be selected by state:modified #9563
Comments
@graciegoheen How would you feel about recommending an in-between solution: # models/path/to/my_model.yml
models:
- name: my_model
config:
materialized: "{{ 'table' if target.name == 'prod' else 'view' }}" Effectively, the same mechanism as in Reasons I like this approach:
|
@jtcohen6 can you help me understand the difference between:
and
Why can we save the raw Jinja text as
It's better than nothing! But still confusing for users that this works in yml files but not in my config block |
It has to do with the way dbt uses Jinja for rendering + storing configs. In the first case, because it's a standalone Jinja expression in yaml, we can save But in the second case, what the user actually provides (no nested curlies except for pre/post-hook) is: {{ config(
materialized = ('table' if target.name == 'prod' else 'view')
) }}
select *
from ... As I understand it, dbt resolves the entire I'm definitely not saying it's impossible, just more difficult to implement. I think the conditional-Jinja-in-yaml case offers us a quicker win with lower lift. |
To support this pattern with Original issue for this: |
I ran into a similar issue recently where we had a macro for selecting the Snowflake warehouse size. Worth calling out that in an ideal world the logic could be encapsulated within a macro that is called within the project file. This is important to avoid redundancy and create more dry code, as well as handle complicated logic more elegantly. It is my understanding that macros cannot be currently referenced in the |
I'd be all-in on jinja-in-yaml if we also put yaml-in-sql 😉 (but seriously: by doing this, we would still have the ability to colocate config with code, if that's what you want). |
Is this your first time submitting a feature request?
Describe the feature
Many folks want to have logic in their dbt project that purposely differs by environment.
For example, let's say I want to materialize a model as a view in
dev
but as a table inprod
.To accomplish this, I use a jinja if statement in my config block:
When selecting
--select state:modified
and comparing mydev
environment to a manifest fromprod
, this model will ALWAYS be marked asmodified
. This is because, the materialized config appears different - inprod
it'stable
, indev
it'sview
.Instead, if I've changed nothing about this model, it shouldn't be marked as modified because the "if" statement/jinja logic hasn't changed.
Describe alternatives you've considered
A current work-around is to move all environment-based logic to my
dbt_project.yml
file.If instead, I were to configure this model as so:
it would NOT be picked up when selecting
--select state:modified
.But this is cumbersome, unexpected, and can lead to an unnecessarily massive
dbt_project.yml
file.Who will this benefit?
Anyone who wants to use
state:modified
and has environment-based logic in their dbt project.Are you interested in contributing this feature?
No response
Anything else?
Potential solution proposed here #3680
This is relevant for all resources that can be configured, not just models.
The text was updated successfully, but these errors were encountered: