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

[CT-3196] [Bug] config block doesn't respect ref('') #8800

Closed
2 tasks done
sudo-pradip opened this issue Oct 10, 2023 · 4 comments
Closed
2 tasks done

[CT-3196] [Bug] config block doesn't respect ref('') #8800

sudo-pradip opened this issue Oct 10, 2023 · 4 comments
Labels
bug Something isn't working wontfix Not a bug or out of scope for dbt-core

Comments

@sudo-pradip
Copy link

sudo-pradip commented Oct 10, 2023

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

  • When I use ref() under model config function, it replace current relation instead of one specified in ref()

Expected Behavior

  • It should just respect ref() under the model config function

Steps To Reproduce

  • For simple explanation purpose only
    • i used ref under the pre_hook, it's not limited to pre_hook
    • also use lame way to create first_model
-- first_model.sql
{{
  config(
    materialized = 'view',
    pre_hook = 'CREATE OR REPLACE TABLE new_table AS SELECT * FROM ' ~ ref('second_model')
    )
}}

SELECT 
    *
FROM
    new_table
  • When I hit dbt build then pre_hook query will generate as below
CREATE OR REPLACE TABLE new_table AS SELECT * FROM mydb.myschema.first_model
  • if we look closely ref('second_model') is replaced with mydb.myschema.first_model, but it suppose to replace mydb.myschema.second_model`

Relevant log output

Began running node model.dbt_materializations_integration_tests.first_model
1 of 1 START sql view model dbt.first_model .................................... [RUN]
Re-using an available connection from the pool (formerly list_awsguzzle_dbt, now model.dbt_materializations_integration_tests.first_model)
Began compiling node model.dbt_materializations_integration_tests.first_model
Writing injected SQL for node "model.dbt_materializations_integration_tests.first_model"
Timing info for model.dbt_materializations_integration_tests.first_model (compile): 16:43:52.871647 => 16:43:52.944055
Began executing node model.dbt_materializations_integration_tests.first_model
Using snowflake connection "model.dbt_materializations_integration_tests.first_model"
On model.dbt_materializations_integration_tests.first_model: /* {"app": "dbt", "dbt_version": "1.6.2", "profile_name": "dbt_red_snow", "target_name": "dev", "node_id": "model.dbt_materializations_integration_tests.first_model"} */
CREATE OR REPLACE TABLE new_table AS SELECT * FROM awsguzzle.dbt.first_model
Opening a new connection, currently in state closed
Snowflake adapter: Snowflake query id: 
Snowflake adapter: Snowflake error: 002003 (42S02): SQL compilation error:
Object 'AWSGUZZLE.DBT.FIRST_MODEL' does not exist or not authorized.

Environment

- OS:Ubuntu 22
- Python:3.10.12
- dbt-core: 1.6.2
- dbt-snowflake: 1.6.2

Which database adapter are you using with dbt?

snowflake

Additional Context

  • If this behaviour is on purpose then it should throw error "Found a cycle: model.dbt_materializations_integration_tests.first_model" right ?
@sudo-pradip sudo-pradip added bug Something isn't working triage labels Oct 10, 2023
@github-actions github-actions bot changed the title [Bug] config block doesn't respect ref('') [CT-3196] [Bug] config block doesn't respect ref('') Oct 10, 2023
@dbeatty10 dbeatty10 self-assigned this Oct 10, 2023
@sudo-pradip
Copy link
Author

sudo-pradip commented Oct 10, 2023

this might be a duplicate issue (sorry my bad)
using {{ ref('anything') }} in a set_sql_header call resolves to the current model and not 'anything' #2793
so what was conclusion ? not to fix and just document it ? issue is open so ...

@dbeatty10
Copy link
Contributor

No worries @sudo-pradip.

I think this comment has the info you are looking for: #6837 (comment)

Could you give that a read, try it out, and let us know what you think?

@dbeatty10 dbeatty10 removed their assignment Oct 10, 2023
@sudo-pradip
Copy link
Author

nice workaround, now it's working, you are kind, thanks you 🌟

{{
  config(
    materialized = 'view',
    pre_hook = "{{ 'CREATE OR REPLACE TABLE new_table AS SELECT * FROM '  ~ ref('second_model') }}"
    )
}}

SELECT 
    *
FROM
    new_table

@dbeatty10
Copy link
Contributor

Awesome @sudo-pradip 🎉 Thanks for sharing your nice example too -- I hadn't tried that variant before 🏆

I'm going to close this as "it's a (complicated) feature, not a bug" 😎

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@dbeatty10 dbeatty10 added wontfix Not a bug or out of scope for dbt-core and removed triage labels Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix Not a bug or out of scope for dbt-core
Projects
None yet
Development

No branches or pull requests

2 participants