-
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] Unittest feature: Inconsistent CTE Naming in dbt Mock Data Causes Query Failures with Aliased Model Names #10728
Comments
Thanks for reaching out about this @megetron3 ! What version of the If you are using
Did you happen to try with dbt-core==1.8.6 dbt-adapters==1.4.1? There are two PRs in dbt-core and dbt-adapters that sound similar to what you described: |
currently using dbt-core 1.8.5 and dbt-adapters==1.6.0. |
@dbeatty10 |
@yonatan-cohen8186 good point about when the database and/or schema differs, but the alias is the same 🧠 Could you open a separate issue for that case? |
I am facing a similar issue but only for the "this" input for incremental model unit tests. For the "this" model, the fixture CTEs are generated using the expected alias name but the model query is instead generated using the model name which causes a similar mismatch as described in this issue. I have tested on latest dbt-core==1.8.6 and dbt-adapters==1.6.0 as well as the suggested dbt-core==1.8.6 dbt-adapters==1.4.1. |
@jtstults-w thanks for reporting this specific case. So that we can capture all the relevant details, could you open a separate issue? |
@jtstults-w I was able to replicate what you described, and I'm going to open an issue shortly along with a reproducible example! |
the suggested combination, dbt-core==1.8.6 and dbt-adapters==1.6.0 - solved the original issue for me and for @yonatan-cohen8186 !
@yonatan-cohen8186 - lets open seperate issue for that as suggested by @dbeatty10 |
Awesome! 🎉
I went ahead and opened this issue #10740, and I will add the details for a reproducible example shortly. SummaryI'll close this particular one as resolved. Instead, we've got these ones which are all similar:
|
@dbeatty10 |
Is this a new bug in dbt-core?
Current Behavior
As for as I understand,
dbt generates the given sources mock_data to be CTEs that are placed before the actual model query starts,
and the model query refers to their data as appose to referring to the actual ref.
The problem is that the CTE's are named according to the convention dbt__cte<mocked_model_name> whereas the model query that's referring to them queries a CTE which is named according to the convention dbt__cte<mocked_model_alias>
This means that the unit tests infra structure is assuming that mocked model name and alias are identical, and will fail otherwise.
That is why when running the the example demonstrated here, it all ran as expected:
And the generated query looked like that:
But as soon as we changed the aliases to mismatch the model names, as the following:
we get this error message:
And the generated query looks like this:
Therefore - the CTE names should be aligned. Either taken from the model name or from the model alias. But it should be consistent all over the generated query
Expected Behavior
we expect the genereted cte to consider the alias used to change the model name
Steps To Reproduce
to reproduce see steps below. in general we would like to create unittest that depends on a model with alias.
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: