-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
target-based Jinja rendering of vars in dbt_project.yml #3105
Comments
Thanks for the bug report @matt-winkler! I get that this is unexpected behavior. The truth is that Ultimately, a solution here would be to clearly establish the parsing order of project files:
I'm definitely interested in rationalizing when
If you do want dbt to handle the database prefixing on the basis of version: 2
sources:
- name: tpch
database: "{{ 'dev_' if target.name == 'dev' else '' }}raw"
tables:
- name: something |
Thanks for the commentary @jtcohen6! Super helpful for you to reinforce that this relates to the parsing order. Agree that adding the jinja to |
After thinking about it a bit more, I do think this represents something novel that hasn't been requested before, though with plenty of overlap with other questions of parse order and Glad you're able to work around this in the meantime! |
On the same boat here. Use Case: As of now how this can be achieved is kind of bundle the SQL transformations into macros and use them in tables, once for each customer. Any other approach? Solution: @jtcohen6 Thoughts? |
Document an exception where `env_vars` is not rendered in the `vars` block of a `dbt_project.yml` file. re: dbt-labs/dbt-core#3105 (comment)
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 remove the stale label or comment on the issue, or it will be closed in 7 days. |
database: "{{ 'dev_' if target.name == 'dev' else '' }}raw" --> can this be changed to if else , we have 4 different targets and so 4 diff db names for each target |
Either use the target.name directly:
or a dictionary:
? Could that work? |
[Preview](https://deploy-preview-3554--docs-getdbt-com.netlify.app/docs/build/project-variables#defining-variables-in-dbt_projectyml) ## What are you changing in this pull request and why? `vars` within `dbt_project.yml` does not support rendering, but it has been requested dbt-labs/dbt-core#3105 and dbt-labs/dbt-core#4314. In the meantime, we want to make it clear within our docs that this isn't supported. See dbt-labs/dbt-core#4314 (comment) for context. ## 🎩 <img width="550" alt="image" src="https://github.com/dbt-labs/docs.getdbt.com/assets/44704949/95e6e65a-028e-4e85-8c56-c4cf12929dc7"> ## Checklist - [x] Review the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) and [About versioning](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#adding-a-new-version) so my content adheres to these guidelines.
I am so much in need of using
but it would be eaiser for people writing the models to just use;
because I could change the policy without having to change all the references |
@moseleyi Have you considered using |
Not sure, would I just pass project and location? and would the vars in dbt_project.yml then work? |
Describe the bug
When compiling / running models from dbt Cloud, the compiler does not correctly evaluate variables defined using jinja in
dbt_project.yml
and referenced in asources:
block.Steps To Reproduce
Create in
dbt_project.yml
:Create in
sources.yml
:Expected behavior
SQL compilation will resolve the variable to either
dev_
or an empty string when running eitherdbt compile
ordbt run
Screenshots and log output
On
dbt compile
:System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
dbt Cloud
The text was updated successfully, but these errors were encountered: