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-1020] [Bug] In python models, dbt.source, dbt.ref doesn't work with multi part names #5634

Closed
2 tasks done
ChenyuLInx opened this issue Aug 9, 2022 · 1 comment · Fixed by #5635
Closed
2 tasks done
Labels
bug Something isn't working python_models

Comments

@ChenyuLInx
Copy link
Contributor

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

Following the steps:

  • get a Jaffle shop dbt project
  • configured dbt_project.yml to point to my snowflake
  • successfully created a sql staging model and ran it
     select * from {{ source('jaffle_shop', 'orders')}}
  • error trying to implement a python staging model
    def model(dbt, session):
        dbt.config(
            materialized='table'
        )
        df = dbt.source("jaffle_shop", "customers")
        
        return df

Error message

19:29:35  Database Error in model stg_jaffle_shop__customers (models/staging/stg_jaffle_shop__customers.py)
19:29:35    100357 (P0000): Python Interpreter Error:
19:29:35    Traceback (most recent call last):
19:29:35      File "_udf_code.py", line 84, in main
19:29:35      File "_udf_code.py", line 9, in model
19:29:35    TypeError: <lambda>() takes 1 positional argument but 2 were given
19:29:35     in function STG_JAFFLE_SHOP__CUSTOMERS__DBT_SP with handler main

Expected Behavior

Run without error

Steps To Reproduce

See Behavior section

Relevant log output

No response

Environment

- OS:
- Python:
- dbt:

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

@ChenyuLInx ChenyuLInx added bug Something isn't working triage labels Aug 9, 2022
@github-actions github-actions bot changed the title [Bug] In python models, dbt.source, dbt.ref doesn't work with multi part names [CT-1020] [Bug] In python models, dbt.source, dbt.ref doesn't work with multi part names Aug 9, 2022
@ChenyuLInx
Copy link
Contributor Author

This is because when we implement the lambda function, we made it only allow 1 argument instead of arbitrary at

def __init__(self, load_df_function) -> None:
self.source = lambda x: source(x, dbt_load_df_function=load_df_function)
self.ref = lambda x: ref(x, dbt_load_df_function=load_df_function)
self.config = config
self.this = this()
self.is_incremental = {{ is_incremental() }}

The fix should just modify the lambda function to something like

lambda *args: source(*args, dbt_load_df_function=load_df_function)

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
Development

Successfully merging a pull request may close this issue.

2 participants