using `{{ ref('anything') }}` in a `set_sql_header` call resolves to the current model and not 'anything'
See original GitHub issueDescribe the bug
Here’s a minimal reproducible example (running on BigQuery).
-- test_tmp_1.sql
{{
config(materialized="table")
}}
select a.* from unnest([
struct(1 as key, 1 as value)
]) as a
-- test_tmp_2.sql
{{
config(materialized="table")
}}
{% call set_sql_header(config) %}
select * from {{ ref('test_tmp_1') }};
{% endcall %}
select * from {{ ref('test_tmp_1') }}
When I dbt run
this project, I get an error when test_tmp_2
is run saying something along the lines of “test_tmp_2 does not exist”.
The output SQL for test_tmp_2
after a dbt run
shows:
select * from `project`.`dataset`.`test_tmp_2`;
create or replace table `project`.`dataset`.`test_tmp_2`
OPTIONS()
as (
select * from `project`.`dataset`.`test_tmp_1`
);
Expected behavior
The ref('test_tmp_1')
call in the call set_sql_header(config)
block should resolve to test_tmp_1
.
Instead it resolves to test_tmp_2
.
System information
Which database are you using dbt with?
- postgres
- redshift
- bigquery
- snowflake
- other (specify: ____________)
The output of dbt --version
:
installed version: 0.18.0
latest version: 0.18.0
Up to date!
Plugins:
- bigquery: 0.18.0
- snowflake: 0.18.0
- redshift: 0.18.0
- postgres: 0.18.0
The operating system you’re using:
macOS 10.15.6
The output of python --version
:
Python 3.8.1
Additional context
N/A
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >Everything You Need to Know About Refs in React
In this post, you will learn how to properly use refs, how to use the current API, and decide when to approach one...
Read more >React: why is that changing the current value of ref from ...
Short answer, no. The only things that cause a re-render in React are the following: A state change within the component (via the...
Read more >Referencing Values with Refs - React Docs Beta
You can access the current value of that ref through the ref.current property. This value is intentionally mutable, meaning you can both read...
Read more >Azure Private Endpoint DNS configuration | Microsoft Learn
Existing Private DNS Zones tied to a single service should not be ... you can adjust the model using the following reference: Azure...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am seeing this issue when I am trying to create a temporary table using set_sql_header with a source. Using snowflake database
Another use case: setting a variable to the result of part of a query, so that it can be referenced in multiple places. BigQuery reevaluates CTEs if they’re queried more than once (I assume there’s some rational behaviour for this, I guess due to parallelisation?) and so the recommended approach is to set a variable to the result and reference it instead.