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

[CT-1545] [Bug] dbt.config.get returns Undefined instead of the default value in Python model #6309

Closed
2 tasks done
devmessias opened this issue Nov 23, 2022 · 3 comments · Fixed by #6317
Closed
2 tasks done
Assignees
Labels
bug Something isn't working python_models
Milestone

Comments

@devmessias
Copy link
Contributor

devmessias commented Nov 23, 2022

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

dbt.config.get("missing_key", "default_value") default value dosen't work. This behavior creates an Undefined variable inside the context after the compilation like this.

config_dict = {'KEY_AVAILABLE': 'everthing_is_ok',  'MISSING_KEY': Undefined}

Expected Behavior

config_dict = {'KEY_AVAILABLE': 'everthing_is_ok',  'MISSING_KEY': "default_value"}

Steps To Reproduce

Define a model like:

def model(dbt, session):

    CONFIG_KEY = dbt.config.get("KEY_EXIST", "DEFAULT_VALUE")
    MISSING_KEY = dbt.config.get("MISSING_KEY", "DEFAULT_VALUE")

    df = dbt.ref("orders")

    return df

With configs like:

version: 2
models:
  - name: something
    config:
      CONFIG_KEY:  everthing_is_ok

Run dbt compile.

The compiled output will create a config_dict like this

config_dict = {'CONFIG_KEY': 'everthing_is_ok',  'MISSING_KEY: Undefined}

In that case, Undefined is a undeclared variable in the context. Because that, this will create an exception.

Relevant log output

No response

Environment

- OS: Linux/Ubuntu
- Python:3.9.12
- dbt-core==1.3.0 
- dbt-databricks==1.3.0

Which database adapter are you using with dbt?

spark

Additional Context

No response

@devmessias devmessias added bug Something isn't working triage labels Nov 23, 2022
@github-actions github-actions bot changed the title [Bug] dbt.config.get returns Undefined instead of the default value in Python model [CT-1545] [Bug] dbt.config.get returns Undefined instead of the default value in Python model Nov 23, 2022
@devmessias
Copy link
Contributor Author

Related to #5846. I can work in a PR to fix that.

@jtcohen6
Copy link
Contributor

@devmessias Good catch, thanks for opening!

This feels like a relatively simple & self-contained fix, so we'd welcome a contribution for it. Let us know if it turns out to be trickier than expected.

@devmessias
Copy link
Contributor Author

@devmessias Good catch, thanks for opening!

This feels like a relatively simple & self-contained fix, so we'd welcome a contribution for it. Let us know if it turns out to be trickier than expected.

You're right! It was a quite simple fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python_models
Projects
None yet
3 participants