-
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
[Regression] Incorrect CTE name in unit tests using incremental
mode for versioned incremental models
#10763
Comments
ReprexCreate these files:
select 2 as id, 1 as event_time
{{
config(
materialized='incremental'
)
}}
select id, event_time
from {{ ref("my_upstream") }}
{% if is_incremental() %}
where event_time >= (select coalesce(max(event_time), 0) from {{ this }} )
{% endif %}
Then run these commands: dbt run --empty --full-refresh
dbt build --select my_model ✅ Everything should run just fine. Then change Then re-run this command: dbt build --select my_model 💥 It will fail with the following output:
As @b-per mentioned, the difference is |
incremental
mode for versioned incremental models
This will likely be a fix in dbt-core, as that's where we set up what 'this' should alias. Here: dbt-core/core/dbt/parser/unit_tests.py Lines 209 to 210 in db69473
|
I think the issue is we're not using the 'latest' version on the tested_node, could perhaps need some updates in find_tested_model_node |
@MichelleArk I wonder if it is fixed by #10755? |
@MichelleArk I tried it out, and #10755 looks like it fixes this issue too. |
Labeling this as a regression since this worked with |
incremental
mode for versioned incremental modelsincremental
mode for versioned incremental models
Is this a new bug?
Current Behavior
When defining a unit test for the incremental load on a versioned incremental model, the generated SQL is invalid. The name of the CTE "injected" at the top contains the version name, when
this
is replaced by the CTE name, but without the version name.e.g., with the versioned model
my_model
we getThis is not valid SQL
Expected Behavior
this
is replaced by the CTE name that includes the version numberSteps To Reproduce
is_incremental: true
and some rows forthis
Relevant log output
Environment
- dbt-adapters:1.6.1
Additional Context
No response
The text was updated successfully, but these errors were encountered: