-
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-2122] [Bug] project variables are None
if dbt.config.get
is called within string interpolation
#6976
Comments
None
if dbt.config.get
is called within string interpolationNone
if dbt.config.get
is called within string interpolation
Hey @mederka thanks for reporting this! This is weird 🌵 I was able to reproduce this when doing a similar setup as you described. I tested two different setups:
My setup included setting a var in version: 2
models:
- name: my_python_model
config:
my_var: my_special_value
another_var: bar Variations that workThese all fully worked: my_value = dbt.config.get("my_var")
print(f"{my_value}") and oddly this too dbt.config.get("my_var")
print(f"{dbt.config.get('my_var')}") and even odder with this backwards ordering print(f"{dbt.config.get('my_var')}")
dbt.config.get("my_var") and this too print(f"{dbt.config.get('my_var')}")
print(f"{dbt.config.get('another_var')}")
dbt.config.get("my_var")
dbt.config.get("another_var") Variations that don't workBut none of these fully worked: print(f"{dbt.config.get('my_var')}") or print(f"{dbt.config.get('my_var')}")
dbt.config.get("another_var") Next stepsI wouldn't expect this to affect users of dbt-snowflake, dbt-bigquery, or dbt-databricks (that aren't also using dbt-fal) because none of them can print to standard out using Python It also worked when I tried shoving I'm going to mark this as |
We statically analyze the My understanding would be, this static analysis works for:
But not when wrapped inside an f-string:
This might be a bit surprising, but it doesn't feel high priority, since there are plenty of ways to work around it. If someone is interested in looking more deeply at how f-strings are represented inside Python's AST... dbt-core/core/dbt/parser/models.py Lines 206 to 209 in 21fae1c
|
Is this a new bug in dbt-core?
Current Behavior
In a Python model like this:
It works fine if I call
dbt.config.get
outside of an interpolated string definition:Expected Behavior
dbt.config.get
should work inside interpolated stringsSteps To Reproduce
On a linux machine, a Python model definition like this:
Will print
my var: None
.Relevant log output
No response
Environment
Which database adapter are you using with dbt?
postgres
Additional Context
Error first reported by a
dbt-fal
user.The text was updated successfully, but these errors were encountered: