# Post-hook Snowflake and Macros

**URL:** <https://discourse.getdbt.com/t/post-hook-snowflake-and-macros/14888>\
**Category:** Help\
**Tags:** snowflake, dbt-cloud\
**Created:** [August 15, 2024, 12:51pm UTC](https://discourse.getdbt.com/t/post-hook-snowflake-and-macros/14888 "2024-08-15T12:51:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikram.chatrath](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@vikram.chatrath](https://discourse.getdbt.com/u/vikram.chatrath)\
**Post date:** [August 15, 2024, 12:51pm UTC](https://discourse.getdbt.com/t/post-hook-snowflake-and-macros/14888/1 "2024-08-15T12:51:22Z")

</div>

Hi

I am struggling to get a post-hook to work after i create a model.

I have a table:

models/liabilities/stg\_liability\_benchmarks\_dates.sql

which gives me a dates and references to run a procedure in snowflake. I envoke the run of the procedure with a macro in dbt:

{% macro iq\_model\_run\_liability\_benchmark() %}  
{{ log(“Running iq\_model\_run\_liability\_benchmark”, info=True) }}  
{% set table\_ref = ref(‘stg\_liability\_benchmarks\_dates’) %}  
{% set query %}  
SELECT LBP\_ID, EFFECTIVE\_DATE  
FROM {{ table\_ref }}  
{% endset %}  
{% set results = run\_query(query) %}

```
{% for row in results.rows %}
    {% set sql_statement %}
        CALL IGG_IQ_DEV.IQ_MODEL.RUN_TASK_LIABILITY_BENCHMARK(True,'{{ row["EFFECTIVE_DATE"] }}','{{ row["LBP_ID"] }}');
    {% endset %}

    {% do run_query(sql_statement) %}
{% endfor %}

```

{% endmacro %}

This works if i manually run-operation iq\_model\_run\_liability\_benchmark after the model stg\_liability\_benchmarks\_dates has run. However i need this to run in sequence of the rest of the models. Namely the macro to run after the stg\_liability\_benchmarks\_dates is finished executing.

I have tried post-hook as a configuration and in the dbt\_project.yml as per this:

```
liabilities:
  +materialized: table
  +schema: liabilities # Matches the folder and schema name
  stg_liability_benchmarks_dates:
    +post-hook: "{{iq_model_run_liability_benchmark()}}"

```

But i get the error: Encountered an error:  
Compilation Error in model stg\_liability\_benchmarks\_dates (models/liabilities/stg\_liability\_benchmarks\_dates.sql)  
‘None’ has no attribute ‘table’

Any idea how to get this to run as a post-hook operation?

---

<div class="post-metadata">

**Author:** ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)\
**Post date:** [August 15, 2024, 5:35pm UTC](https://discourse.getdbt.com/t/post-hook-snowflake-and-macros/14888/2 "2024-08-15T17:35:42Z")

</div>

its a compilation error. Could you please share ur model code

---

<div class="post-metadata">

**Author:** ![vikram.chatrath](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@vikram.chatrath](https://discourse.getdbt.com/u/vikram.chatrath)\
**Post date:** [August 15, 2024, 6:53pm UTC](https://discourse.getdbt.com/t/post-hook-snowflake-and-macros/14888/3 "2024-08-15T18:53:23Z")

</div>

# Name your project! Project names should contain only lowercase characters

# and underscores. A good package name should reflect your organization’s

# name or the intended use of these models

name: “igg\_iq”  
version: “1.0.0”  
config-version: 2

# This setting configures which “profile” dbt uses for this project.

profile: “default”

# These configurations specify where dbt should look for different types of files.

# The `model-paths` config, for example, states that models in this project can be

# found in the “models/” directory. You probably won’t need to change these!

model-paths: [“models”]  
analysis-paths: [“analyses”]  
test-paths: [“tests”]  
seed-paths: [“seeds”]  
macro-paths: [“macros”]  
snapshot-paths: [“snapshots”]

target-path: “target” # directory which will store compiled SQL files  
clean-targets: # directories to be removed by `dbt clean`

- “target”
- “dbt\_packages”

# Configuring models

# Full documentation: [Model configurations | dbt Developer Hub](https://docs.getdbt.com/docs/configuring-models)

# In dbt, the default materialization for a model is a view. This means, when you run

# dbt run or dbt build, all of your models will be built as a view in your data platform.

# The configuration below will override this setting for models in the example folder to

# instead be materialized as tables. Any models you add to the root of the models folder will

# continue to be built as views. These settings can be overridden in the individual model files

# using the `{{ config(...) }}` macro.

models:  
igg\_iq:  
market\_curves:  
+schema: market\_curves  
benchmarks:  
+materialized: table  
+schema: benchmarks  
esg\_analytics:  
+materialized: table  
+schema: esg\_analytics  
platform\_admin:  
+schema: platform\_admin  
portfolio\_holdings:  
+materialized: table  
+schema: portfolio\_holdings  
portfolios:  
+materialized: table  
+schema: portfolios  
securities:  
+materialized: table  
+schema: securities  
security\_info:  
+materialized: table  
+schema: security\_info  
security\_info\_bbg:  
+materialized: table  
+schema: security\_info\_bbg  
market\_bond\_curves:  
+materialized: table  
+schema: market\_bond\_curves  
market\_derivatives\_ois\_curves:  
+materialized: table  
+schema: market\_derivatives\_ois\_curves  
market\_derivatives\_inflation\_curves:  
+materialized: table  
+schema: market\_derivatives\_inflation\_curves  
oversight:  
+materialized: table  
+schema: oversight  
liabilities:  
+materialized: table  
+schema: liabilities  
stg\_liability\_benchmarks\_dates:  
+materialized: table  
+post-hook: “{{ iq\_model\_run\_liability\_benchmark() }}”  
balance\_sheets:  
+materialized: table  
+schema: balance\_sheets  
analytics:  
+materialized: table  
+schema: analytics  
LDI\_characteristics:  
+materialized: table  
+schema: LDI\_characteristics  
fee\_data:  
+materialized: table  
+schema: fee\_data  
packages:

- package: dbt-labs/dbt\_utils  
version: 0.9.6

---

<div class="post-metadata">

**Author:** ![vikram.chatrath](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@vikram.chatrath](https://discourse.getdbt.com/u/vikram.chatrath)\
**Post date:** [August 15, 2024, 6:54pm UTC](https://discourse.getdbt.com/t/post-hook-snowflake-and-macros/14888/4 "2024-08-15T18:54:09Z")

</div>

Thanks for your help @Surya
