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

Create dbt.var.get() for python models to retrieve project variables without a yaml file #10914

Open
3 tasks done
hope-wat opened this issue Oct 24, 2024 · 3 comments · May be fixed by #10932 or dbt-labs/dbt-adapters#339
Open
3 tasks done
Labels
enhancement New feature or request triage

Comments

@hope-wat
Copy link

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

Create dbt.var.get() for python models to retrieve project variables without requiring yaml file.

I am narrowly requesting a var feature. However, this can be a small part of a larger initiative to get python at parity with SQL.

Describe alternatives you've considered

Here is a loom walking through the today solution.

The tl;dr is that python models don't have an argument such as dbt.var.get(). We have a dbt.config.get() but that argument is specific to each model (not global).
What we need to do today:

  1. Give the model a passthrough variable for example, run_frequency.
  2. Make a model specific yaml for your python model. This is really we need to do all python model configs if we want SQL parity.
  3. Define the default you want, in this case 'Daily' in the dbt_project.yml.
  4. Pass the variable override in the command line as usual, in our example, 'Weekly'. So dbt run -s model_name --vars '{"run_frequency": "Weekly"}'

Who will this benefit?

Our user base that is using python. I realize this is not the majority of users, but it would boost the python experience up to reduce the user experience and ergonomics divide between python and SQL in dbt.

Are you interested in contributing this feature?

Yes, I can be a tester.

Anything else?

No response

@hope-wat hope-wat added enhancement New feature or request triage labels Oct 24, 2024
@devmessias
Copy link
Contributor

I really like this!

Our user base that is using Python

One challenge with adopting Python models is the limitations as you describe here, as well as PR like #8538. At my previous job, I was able to advocate for Python models due PySpark and able to test transformations, but it wasn’t without costs, as I encountered some limitations.

If @hope-wat can help with testing, I’d be happy to help implement this. I have some experience with how Python models work, because of #6317 and #8538.

@devmessias
Copy link
Contributor

I believe it's a good idea to continue allowing default values inside dbt.config.get because SQL models allow us to do the same within Jinja code

@devmessias
Copy link
Contributor

I thought a bit about how to do implement, and it's easy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage
Projects
None yet
2 participants