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

[Bug] unit test use source name for cte name and source identifier for table name #10667

Closed
2 tasks done
zhoujia74 opened this issue Sep 5, 2024 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working duplicate This issue or pull request already exists unit tests Issues related to built-in dbt unit testing functionality

Comments

@zhoujia74
Copy link

zhoujia74 commented Sep 5, 2024

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

I try to unit test a model that has a source table configured with both identifier and name. When we run the unit test, the test fails with error

TABLE_NOT_FOUND: line xxx:xx: Table 'xxx.__dbt__cte__test' does not exist.

source config:

  tables:
  - identifier: test
    name: test_table

model.sql:
select * from {{ source("test_table") }}

After checking the log, the generated sql uses source name for the generated cte name and source identifier to replace the source table name.

__dbt__cte__test_table as ( xxxx ) select * from __dbt_cte__test

If we rename the source identifier to match the name, then the error will be gone.

Expected Behavior

unit test should use same way to generate both the cte name and source table name

Steps To Reproduce

Follow the steps in the current behavior.

Relevant log output

No response

Environment

- OS: mac
- Python: 3.10.2
- dbt: both 1.8.4 and 1.8.6

Which database adapter are you using with dbt?

other (mention it in "Additional Context")

Additional Context

dbt-athena adapter

@zhoujia74 zhoujia74 added bug Something isn't working triage labels Sep 5, 2024
@dbeatty10 dbeatty10 added the unit tests Issues related to built-in dbt unit testing functionality label Sep 5, 2024
@dbeatty10
Copy link
Contributor

Thanks for raising this issue @zhoujia74 !

What version of the dbt-adapters package do you have installed?

If you are using pip to install dbt, you can do a command like the following to get that version:

pip freeze | grep dbt-adapters

If I try a scenario like you described with dbt-core==1.8.6 dbt-adapters==1.4.0, then I get an error message similar to you.

But if I try it again with dbt-core==1.8.6 dbt-adapters==1.4.1, then it works.

@zhoujia74
Copy link
Author

@dbeatty10 Thank you for looking into this. I just did some tests with different dbt versions. I can reproduce the error with dbt-core 1.8.4 and dbt-adapters 1.4.1. It works fine with dbt-core 1.8.6 and dbt-adapters 1.4.1. With what you finds on dbt-core 1.8.6 and dbt-adapters 1.4.0. Not sure which package is the real cause. Maybe something was fixed in both dbt-core and dbt-adapters. Anyway glad to know the latest versions work. Thanks you.

@dbeatty10
Copy link
Contributor

Maybe something was fixed in both dbt-core and dbt-adapters.

It was!

There are two PRs in dbt-core and dbt-adapters that need to work in concert with each other:

So either of these combinations will have the desired behavior ✅ , but anything else will not ❌ :

  • dbt-core>=1.8.6 and dbt-adapters>=1.4.1, or
  • dbt-core<1.8.6 and dbt-adapters<1.4.1

Since this is working for you now with the latest versions, I'm going to close this as already covered. But please reach out if you run into anything else.

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2024
@dbeatty10 dbeatty10 added duplicate This issue or pull request already exists and removed triage labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

No branches or pull requests

2 participants