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

[Regression] since 1.4.1, generate_alias_name overrides and refs to ephemeral models dont work anymore #284

Open
2 tasks done
rompetroll opened this issue Aug 21, 2024 · 4 comments
Labels
bug Something isn't working regression

Comments

@rompetroll
Copy link

Is this a regression?

  • I believe this is a regression in functionality
  • I have searched the existing issues, and I could not find an existing issue for this regression

Current Behavior

the CTE block for an ephemaral model is generated using the filename of the model as alias, but in places where the ephemaral model is referenced, the ref is replaced with a non-existent CTE alias, which seems to be constucted using the generate_alias_name macro.

Expected/Previous Behavior

CTE block alias and alias in ref resolution should match, to that queries become valid.

Steps To Reproduce

  1. define a generate_alias_name macro which modifies model names
  2. have an ephemeral model
  3. reference the ephemeral model in another model
  4. try to run

Relevant log output

No response

Environment

- OS:linux
- Python:3.10.14+3.11.8
- dbt-adapters (working version):1.4.0
- dbt-adapters (regression version):1.4.1

Additional Context

No response

@dbeatty10
Copy link
Contributor

Thanks for reporting this @rompetroll !

I was able to reproduce an error even without a customized generate_alias_name when using dbt-core 1.8.5 and dbt-adapters 1.4.1 (python -m pip show dbt-core dbt-adapters). See "reprex" below for details

Root cause

I'm guessing this was related to some combination of #236 and dbt-labs/dbt-core#10290.

Specifically, #236 was merged on Aug 8, 2024 and dbt-adapters 1.4.1 was released the next day on Aug 9, 2024. However, dbt-labs/dbt-core#10290 was merged on Aug 9, 2024, after dbt-core 1.8.5 was released on Aug 7, 2024. And it was only merged to the main branch and not backported to v1.8, so the changes in dbt-core are not yet available.

Workarounds

Three main options in the meantime:

  1. Downgrade to dbt-adapters 1.4.0
  2. Remove alias configs in ephemeral models
  3. Convert ephemeral models to either view or table models

I'm guessing most would want to choose the 1st option rather than the other two.

Reprex

Here's the files and commands I used:

models/my_ephemeral_model.sql

{{ config(
    materialized="ephemeral",
    alias="ignored_until_now",
   )
}}

select 1 as id

models/my_table_model.sql

{{ config(materialized="table") }}

select *
from {{ ref("my_ephemeral_model") }}

Run this command:

dbt build -s my_table_model

Examine the compiled SQL code and see the mismatch:

target/compiled/my_project/models/my_table_model.sql

with __dbt__cte__my_ephemeral_model as (


select 1 as id
) select *
from __dbt__cte__ignored_until_now

@mikealfare
Copy link
Contributor

mikealfare commented Aug 26, 2024

@dbeatty10 In an effort to be very explicit, the expectation is that this:

with __dbt__cte__my_ephemeral_model as (


select 1 as id
) select *
from __dbt__cte__ignored_until_now

should be this:

with __dbt__cte__ignored_until_now as (


select 1 as id
) select *
from __dbt__cte__ignored_until_now

Correct?

@dbeatty10
Copy link
Contributor

Yep, you got it @mikealfare 👍

The root cause is that #236 and dbt-labs/dbt-core#10290 are coupled and need to go together.

The expectation is that when dbt-adapters>=1.4.1 it would be:

with __dbt__cte__ignored_until_now as (

select 1 as id
) select *
from __dbt__cte__ignored_until_now

And we'd also expect that dbt-adapters<=1.4.0 would be:

with __dbt__cte__my_ephemeral_model as (


select 1 as id
) select *
from __dbt__cte__my_ephemeral_model

@jeancochrane
Copy link
Contributor

@rompetroll @dbeatty10 @mikealfare I've only done preliminary testing at this point, but it seems like this is resolved in v1.8.6, correct?

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

No branches or pull requests

4 participants