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

python model reference f"{dbt.ref('test5')}" #4838

Closed
FishtownBuildBot opened this issue Jan 31, 2024 · 5 comments · Fixed by #4965
Closed

python model reference f"{dbt.ref('test5')}" #4838

FishtownBuildBot opened this issue Jan 31, 2024 · 5 comments · Fixed by #4965
Assignees
Labels
content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core dbt-core v1.8 improvement Use this when an area of the docs needs improvement as it's currently unclear size: x-small This change will take under 3 hours to fix.

Comments

@FishtownBuildBot
Copy link

FishtownBuildBot commented Jan 31, 2024

f"{dbt.ref('test5')}"

is now a supported way to reference a model in a python model

cc: @ChenyuLInx

@runleonarun runleonarun added content Improvements or additions to content improvement Use this when an area of the docs needs improvement as it's currently unclear dbt Core The changes proposed in this issue relate to dbt Core labels Jan 31, 2024
@jtcohen6 jtcohen6 added this to the dbt Core v1.8 Documentation milestone Feb 7, 2024
@graciegoheen graciegoheen changed the title Docs Changes Needed from dbt-core PR #9162 python model reference f"{dbt.ref('test5')}" Feb 13, 2024
@runleonarun
Copy link
Collaborator

@runleonarun adding Copilot summary

This pull request primarily focuses on fixing the parsing of f-strings in Python models. The changes include adding support for dbt function calls in f-strings, modifying test cases to include f-string usage, and adding a new test case specifically for f-string configuration.

Fixes and improvements:

.changes/unreleased/Fixes-20231128-102111.yaml: Announced the fix for parsing f-strings in Python models.
Changes to the Python model parser:

core/dbt/parser/models.py: Added support for dbt function calls in f-strings. This change allows the parser to correctly interpret dbt function calls that are embedded within f-strings.
Changes to the test cases:

tests/unit/test_parser.py: Modified the model function to include f-string usage. This change tests the parser's ability to correctly interpret f-strings.
tests/unit/test_parser.py: Added a new Python model that uses f-strings. This model is used in a new test case that verifies the correct parsing of f-strings.
tests/unit/test_parser.py: Modified the test_python_model_parse function to include a new reference argument that uses f-strings. This change tests the parser's ability to correctly interpret reference arguments within f-strings.
tests/unit/test_parser.py: Added a new test case test_python_model_f_string_config to verify the correct parsing of f-string configuration in Python models.

@graciegoheen graciegoheen added the size: x-small This change will take under 3 hours to fix. label Feb 14, 2024
@mirnawong1 mirnawong1 self-assigned this Feb 15, 2024
@mirnawong1
Copy link
Contributor

thank you @runleonarun ! working on this now!

@mirnawong1
Copy link
Contributor

hey @ChenyuLInx are we saying there is now another way to ref python models? so:

or is the f string the new and only way? also is there any change when referencing in downstream models (e.g. select * from {{ ref('my_python_model') }})?

@mirnawong1
Copy link
Contributor

hey @ChenyuLInx , friendly nudge if you have any clarification on this pls? thank you!

@ChenyuLInx
Copy link
Contributor

Hey @mirnawong1 , the change means that when using a config in a python f string, the config will be available in python models. Here's an example:
If my_var config for the current model is 5, before this change,

print(f"{dbt.config.get('my_var')}")

will be None, but after this change, it will actually print 5.

mirnawong1 added a commit that referenced this issue Feb 23, 2024
this pr adds a new code change that support for dbt function calls in
f-strings.

added section on how to dynamically access this. 

Resolves #4838
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content dbt Core The changes proposed in this issue relate to dbt Core dbt-core v1.8 improvement Use this when an area of the docs needs improvement as it's currently unclear size: x-small This change will take under 3 hours to fix.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants