-
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
[Bug] Relation within dbt_utils macro is not honoring the --defer
flag
#11019
Comments
Thanks for reporting this @emilee-jurkowski ! Did you happen to try something like this? {% set model_reference = ref('model_a') %}
{% set val_list = dbt_utils.get_column_values(table=model_reference, column='VAL') %} I didn't try it myself, but curious if it behaves different or the same as what you are seeing with this: {% set val_list = dbt_utils.get_column_values(table=ref('model_a'), column='VAL') %} |
@dbeatty10 I did try something like that and it appears to have the same issue |
See below for something that worked for me. Could you let me know if it doesn't work for you? It looks like the key bit is making sure to fully build the environment that is being deferred to. I got the same error as you when I didn't fully build the production environment first. But once I built the production environment, then the commands worked without error. Alternatively, you can use the {% set val_list = dbt_utils.get_column_values(table=ref('model_a'), column='id', default=[]) %} ExampleCreate these files:
{{ config(materialized='table') }}
select 1 as id
{{ config(materialized='table') }}
{% set val_list = dbt_utils.get_column_values(table=ref('model_a'), column='id') %}
{% for val in val_list %}
-- , '{{ val }}' as val
select *
from {{ ref('model_a') }}
{%- endfor -%}
Run these commands to create a production ("prod") environment and defer to it when compiling the development ("dev") environment: dbt build --target-path artifacts --target prod
dbt compile -s model_b --defer --state artifacts --target dev Get this output:
Run this command: dbt run -s model_b+1 --defer --state artifacts --target dev Get this output:
|
--defer
flag
@dbeatty10 I did some testing and realized that I was wrong about what the issue is. The dbt build is honoring the defer flag with the macro like you showed above. We are actually running into an issue when trying to execute |
@emilee-jurkowski I'm not quite following your example. Could you share the following?
If you can provide those pieces, then that will help me assess if dbt is operating differently than it is designed. |
If I run |
@emilee-jurkowski Yeah, running I'm going to close this as resolved since we got to the bottom of things and dbt is behaving as we expect. If you'd like to see any changes/additions to the dbt product documentation, you can reach out to our Docs team by opening an issue in the Abbreviated history of
|
Is this a new bug in dbt-core?
Current Behavior
In my model_b.sql I have something like
{% set val_list = dbt_utils.get_column_values(table=ref('model_a'), column='VAL') %}
. I try to run a dbt build using a defer flag. model_a does not exist in the the db & schema that I am building in, yet it still will not use the db & schema I am telling it to defer to. When I rundbt ls -s 1+model_b
, dbt does recognize that model_a is upstream and being referred to.Expected Behavior
In the above example, the dbt_utils macro should use the defer db & schema to get the column values from model_a.
Steps To Reproduce
I have model_b like such
Then run
dbt run -s model_b+1
in the dev environment with a defer to the prod environment.Relevant log output
Environment
Which database adapter are you using with dbt?
snowflake
Additional Context
No response
The text was updated successfully, but these errors were encountered: