-
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
[Bug] config.get(config.field, default_value) not working properly? #4273
Comments
@hui-zheng You're right! This is a duplicate of a much older issue, one we closed a while ago: #2441. @gshank It looks like you resolved that issue after v0.20, and I agree we got 90% of the way there, by making dbt-core/core/dbt/context/providers.py Lines 328 to 329 in 0722922
dbt-core/core/dbt/context/providers.py Lines 372 to 373 in 0722922
I think the resolution to this issue would be as simple as switching the argument order: def get(self, name, default=None, validator=None):
return '' def get(self, name, default=None, validator=None):
to_return = self._lookup(name, default) That way, This would be a big breaking change. v1 is absolutely the right time to do it; v1 after we've already put out the first release candidate, not as much. Reasons I'm still open to this:
So, what do we think of making this change? @hui-zheng As an unrelated point: Where did you see |
I think the 'get' in the providers is not where config.get() ought to be... that should be the get def in BaseConfig. Let me play with this a bit. |
The python dictionary get method only returns the default if the key doesn't exist. So if 'enable_refresh' is set to None in the config, that's what it will return, without regard to the default. I'm thinking that this should work how it does in Python, which it does right now. |
@gshank If that's the case, I'd expect: -- models/any_model.sql
select {{ config.get('made_up_nonexistent_key', 'default_value') }} as col_value To compile to: select 'default_value' as col_value Instead of (current): select None as col_value |
It works in Python. I think Jinja does something to the arguments. |
You're right, it's the 'get' method in the RuntimeConfigObject. I didn't realize that we were wrapping that there. What is the 'validator' used for? |
My proposal is that we remove the 'validator' keyword argument from 'get' and 'require'. All it does is pass along and execute the passed in function with the value, which can be done in the template if that's wanted. No tests failed. Do you know of anybody who uses it? |
Offhand, I know of exactly two places (really one place) where My vote might be to reverse the order of the keyword arguments, but I'd be okay with removing |
We can leave it in place. |
This was fixed with PR #4297. It didn't automatically close because I incorrectly put the ticket number as 4272 |
Is there an existing issue for this?
Current Behavior
for the code below in adapters,
When the field
enable_refresh
is not set by model config, a default valuefalse
is not used byconfig.get()
.Instead, enable_refresh is set to
none
.Expected Behavior
for the code below in adapters,
When the field
enable_refresh
is not set by model config, a default valuefalse
shall be used.enable_refresh
shall be set to `false.Interestingly, if I use the code below, it works as expected.
Steps To Reproduce
Background
I came across this unexpected behavior when I tried to upgrade BQ
materialized_view
in dbt-labs-experimental-features to work with dbt 0.21.0If I have a model materialized_view_A.
Not setting the
enable_refresh
field in the model config.in
bigquery__create_materialized_view_as
macro,if you log the value of
enable_refresh
, you will see it's set tonone
, which is unexpected.Now, if you change the code to
if you log the value of
enable_refresh
, you will see it's set tofalse
, which is expected.Relevant log output
No response
Environment
What database are you using dbt with?
bigquery
Additional Context
No response
The text was updated successfully, but these errors were encountered: