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

[Feature] Support references to ephemeral models in hooks #10033

Open
3 tasks done
siljamardla opened this issue Apr 25, 2024 · 1 comment
Open
3 tasks done

[Feature] Support references to ephemeral models in hooks #10033

siljamardla opened this issue Apr 25, 2024 · 1 comment
Labels
enhancement New feature or request ephemeral Issues related to dbt's ephemeral materialization hooks Issues related to dbt's hooks functionality

Comments

@siljamardla
Copy link

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

I have a macro that is called in a post-hook.
In that macro I have used a reference to a staging table stg_XX that has ephemeral materialisation.
When running my model that calls this post-hook, I get the following error:

Runtime Error in model XXX (models/XXX.sql)
  [TABLE_OR_VIEW_NOT_FOUND] The table or view `__dbt__cte__stg_XX` cannot be found. Verify the spelling and correctness of the schema and catalog.
  If you did not qualify the name with a schema, verify the current_schema() output, or qualify the name with the correct schema and catalog.
  To tolerate the error on drop use DROP VIEW IF EXISTS or DROP TABLE IF EXISTS.;

Describe alternatives you've considered

When I switch the staging table to view materialisation, I no longer get the same error.

However, going with this option forces me to turn my staging models from ephemeral to views, which has its own downsides and upsides. Having the possibility to use staging models in hooks should not make me decide.

Who will this benefit?

Anyone who wants to reference ephemeral models in hooks.

Are you interested in contributing this feature?

No response

Anything else?

Low priority, just want to point out the unexpected behaviour.

Found a few other references about this topic:
https://stackoverflow.com/questions/64622026/how-to-refer-ephemeral-model-in-pre-post-hook-of-an-incremental-model?newreg=637b64465aca4988a305856104481766
https://discourse.getdbt.com/t/how-to-refer-ephemeral-model-in-pre-post-hook-of-an-incremental-model/1763
Might be related: https://discourse.getdbt.com/t/how-to-use-sources-inside-a-post-hook/10638

@siljamardla siljamardla added enhancement New feature or request triage labels Apr 25, 2024
@dbeatty10 dbeatty10 added hooks Issues related to dbt's hooks functionality ephemeral Issues related to dbt's ephemeral materialization labels Apr 25, 2024
@dbeatty10
Copy link
Contributor

Thanks for reporting this @siljamardla !

I see what you are saying about using an ephemeral model in a post hook. It looks to me like the reference is being added the SQL just fine -- the only piece missing is that it isn't injecting the necessary CTE.

I tried out using a source instead of a ref to an ephemeral model, and that worked fine. So this one is not related: https://discourse.getdbt.com/t/how-to-use-sources-inside-a-post-hook/10638 .

Options

There's a few approaches we could take here:

  1. Fully support ephemeral models within hooks
  2. Raise a helpful error message during parsing or compilation instead saying this isn't supported
  3. Status quo

Priority and workaround

Agreed that this would be a low priority for us, so I'm guessing we'll choose to keep the status quo on this one.

In the meantime, we'd recommend using either a table or view materialization as a workaround.

Here's the small dbt project I used to try out the scenario you described:

Reprex

models/my_ephemeral_model.sql

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

select 1 as id

models/my_model.sql

{{ config(
    post_hook="select * from {{ ref('my_ephemeral_model') }}"
) }}

select 1 as id
dbt run -s my_model

@dbeatty10 dbeatty10 removed the triage label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ephemeral Issues related to dbt's ephemeral materialization hooks Issues related to dbt's hooks functionality
Projects
None yet
Development

No branches or pull requests

2 participants