-
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
[CT-2769] [Feature] Allow yaml/jinja to get rendered with additional context #8000
Comments
@kdazzle Thanks for the thoughtful write-up! I'm not sure if you're asking for the same (or similar) capability as Maxime last year: methods written in Python, callable from the Jinja contxt. Here's what I wrote about it then: |
Thanks for the response @jtcohen6. Nice memory 😄 - it does look like I'm proposing the same thing as Maxime. I'll take a look into the plugin approach. I'm a big fan of dbt, but have found that I'm wrestling with the tool, and that allowing more flexibility for developers could be helpful as the audience expands. Although my issues could be a learning curve thing, or maybe plugins are the solution. Thanks again! |
@kdazzle If there are specific things you've been trying to accomplish, where you've found yourself wrestling / working against the grain — I'd be curious to hear more about them! dbt is an opinionated tool, in that there are common use cases in data/analytics engineering that we want to make easy — at the same, there's a lot that's possible, because the framework has some flexibility built in, especially via user-space Jinja. Sometimes, a use case is totally legitimate, and still harder than it should be. In those cases, we want to hear more & discuss what a better built-in solution could look like, or which building blocks we're missing that would make it easier. |
Hi @jtcohen6 - here are a couple of examples. They're just little frustrations, nothing major, but I've been a Python developer for a while, so I'm used to being able to override/extend functionality (like in, say, Django Rest Framework). Generally, I try to stay away from doing too much in Jinja, since it's just a templating language. I'm integrating dbt into an existing code/database with lots of users, instead of starting fresh. There's a lot of existing infrastructure and roles already defined. Examples:
But that doesn't work for a couple reasons (one being some static analysis that prevents using variables?) However, I haven't actually tried this too much yet, and the solution might be as simple as defining a dictionary in the dbt config and referencing that in the notebook/config.
Anyways, I appreciate all your work, and thanks for the help! |
Heard! It sounds like there are two main limitations you're running into:
Hear you on this one too. The lack of code reusability across Python models (akin to Jinja macros for SQL models) is definitely something we've heard from folks who are looking to scale out their adoption. Again, I hesitate to release Jinja macros for DRY-ly templating Python into the world, as I feel like there are better options here — but it isn't something we've been able to prioritize as an area of focus this year. |
@kdazzle created discussion here dbt-labs/dbt-adapters#259 IMO Adapter factory should allow user provided customized adapter class |
Is this your first time submitting a feature request?
Describe the feature
Right now, context used to render yaml files can be passed through the cli or the profile. It would be nice if there was also a hook to allow developers to define additional context variables. I imagine there could be a file like
macros/context.py
that would define a functionget_context(target) -> dict
or something like that.The hook seems like it would be in
core/dbt/config/renderer.DbtprojectYamlRenderer
(maybe in the init where the rest of the context building seems to happen?). Regardless of where it ended up, the yaml hook could look like:I haven't looked into how Jinja could tie in, but I'm hoping it would be as straightforward.
Thanks!
Describe alternatives you've considered
Setting a bunch of variables using Jinja, setting variables in yaml, which is usually fine, but not as nice
Who will this benefit?
Projects that might have non-standard setups, want a little more flexibility, and are more comfortable writing code
Are you interested in contributing this feature?
yes
Anything else?
No response
The text was updated successfully, but these errors were encountered: