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

[Bug] The "this" object returns the default profile schema not the correct schema when passed into a macro running in a post hook #11318

Closed
2 tasks done
stevensnicholas opened this issue Feb 18, 2025 · 1 comment
Labels
bug Something isn't working triage

Comments

@stevensnicholas
Copy link

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 using the this object to pass into a macro on the post_hook config the schema is correct and incorrect at different stages. Sometimes using the correct schema logic and sometimes defaulting just the schema provided in the profile

Expected Behavior

The this.schema always resolves to consistent logic or is none if schema is not available at a given stage.

Steps To Reproduce

  1. Standard DBT starter project
  2. Profile set up with a schema set "profile_schema"
{{ 
    config(
        materialized='table',
        schema='test_schema',
        post_hook= a_macro( this )
    
) }}

Added to models/example/my_first_dbt_model.sql
4. New macro added to macros/a_macro.sql


{% macro a_macro(source_model) %}

    {{ log("Source is: " ~ source_model , info=execute ) }}
    select '{{ source_model }}';

{% endmacro %}

dbt run --select my_first_dbt_model

Relevant log output

In console output logs 
04:48:49  1 of 1 START sql table model profile_schema_test_schema.my_first_dbt_model ......... [RUN]
04:48:49  Source is: "dev"."profile_schema_test_schema"."my_first_dbt_model"
04:48:51  1 of 1 OK created sql table model profile_schema_test_schema.my_first_dbt_model .... [SUCCESS in 1.94s]
-------------------------
When looking at the logs to see what the posthook did run 

select '"dev"."profile_schema"."my_first_dbt_model"';

Environment

- OS: wsl Ubuntu
- Python: 3.12
- dbt: 1.9.2
tested on snowflake and Redshift adapter

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

@stevensnicholas stevensnicholas added bug Something isn't working triage labels Feb 18, 2025
@b-per
Copy link
Contributor

b-per commented Feb 18, 2025

Hi. This is not a bug. You need to wrap this in {{ }}. So, you need to have:

{{ 
    config(
        materialized='table',
        schema='test_schema',
        post_hook= a_macro( {{ this }}  )
    
) }}

This is described here and mentioned here as well.

@b-per b-per closed this as completed Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants