You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the existing issues, and I could not find an existing issue for this bug
Current Behavior
{{ this }} evaluates to the correct full path of the table in Snowflake when used directly in a model's pre-hook/post-hook.
When it is passed from a model as an argument to a macro, only the table name information is retained and the Snowflake schema and database information is lost.
Expected Behavior
When {{ this }} is passed from a model to the macro, the schema and database info is not lost.
Steps To Reproduce
When using {{ this }} directly in a post_hook, it correctly evaluates to the full path of the table in Snowflake.
{{ config(
post_hook=[
"grant select on {{this}} to role DW_GL"
]
)}}
In the above example, {{this}} would evaluate to PRESENTATION.B2B.MY_DBT_MODEL_NAME, which is as intended.
Now I want to take this logic and put it into a macro.
I created a macro as below:
{% macro grant_select(table_name, roles) %}
-- Macro to grant select on table to one or more roles.
{% for role in roles %}
grant select on {{ table_name }} to role {{role}}
{% endfor %}
{% endmacro %}
Now when the macro runs, this is passed to the macro as the table_name variable.
However it now evaluates to RAW.PUBLIC.MY_DBT_MODEL_NAME.
RAW.PUBLIC is my default schema in Snowflake. The actual database and schema info is lost when passing through to the macro.
Relevant log output
08:00:50 Database Error in model vw_bfn_d365dimretailstore (models/presentation/bfn_presentation/vw_bfn_d365dimretailstore.sql)
08:00:50 002003 (42S02): SQL compilation error:
08:00:50 Table 'RAW.PUBLIC.VW_BFN_D365DIMRETAILSTORE' does not exist or not authorized.
Note: Does not exist because table is created at `PRESENTATION96447.BFN_PRESENTATION.vw_bfn_d365dimretailstore`
github-actionsbot
changed the title
[Bug] {{this}} evaluates incorrectly with Snowflake when used in a macro
[CT-2338] [Bug] {{this}} evaluates incorrectly with Snowflake when used in a macro
Mar 29, 2023
Is this a new bug in dbt-core?
Current Behavior
{{ this }}
evaluates to the correct full path of the table in Snowflake when used directly in a model's pre-hook/post-hook.When it is passed from a model as an argument to a macro, only the table name information is retained and the Snowflake schema and database information is lost.
Expected Behavior
When
{{ this }}
is passed from a model to the macro, the schema and database info is not lost.Steps To Reproduce
When using
{{ this }}
directly in a post_hook, it correctly evaluates to the full path of the table in Snowflake.In the above example,
{{this}}
would evaluate toPRESENTATION.B2B.MY_DBT_MODEL_NAME
, which is as intended.Now I want to take this logic and put it into a macro.
I created a macro as below:
In the model I call the macro as below:
Now when the macro runs,
this
is passed to the macro as thetable_name
variable.However it now evaluates to
RAW.PUBLIC.MY_DBT_MODEL_NAME
.RAW.PUBLIC
is my default schema in Snowflake. The actual database and schema info is lost when passing through to the macro.Relevant log output
Environment
Which database adapter are you using with dbt?
snowflake
Additional Context
N/A
The text was updated successfully, but these errors were encountered: