JavaScript
x
12
12
1
{{
2
config (
3
pre_hook = before_begin("{{audit_tbl_insert(1,'stg_news_sentiment_analysis_incr') }}"),
4
post_hook = after_commit("{{audit_tbl_update(1,'stg_news_sentiment_analysis_incr','dbt_development','news_sentiment_analysis') }}")
5
)
6
}}
7
8
select rd.news_id ,rd.title, rd.description, ns.sentiment from live_crawler_output_rss.rss_data rd
9
left join
10
live_crawler_output_rss.news_sentiment ns
11
on rd.news_id = ns.data_id limit 10000;
12
This is my model in DBT which is configured with pre and post hooks which referance a macro to insert and update the audit table.
my macro
JavaScript
1
11
11
1
{ % macro audit_tbl_insert (model_id_no, model_name_txt) % }
2
3
{% set run_id_value = var('run_id') %}
4
5
insert into {{audit_schema_name}}.{{audit_table_name}} (run_id, model_id, model_name, status, start_time, last_updated_at)
6
values
7
({{run_id_value}}::bigint,{{model_id_no}}::bigint,{{model_name_txt}},'STARTED',current_timestamp,current_timestamp)
8
9
{% endmacro %}
10
11
this is the first time i’m using this macro and I see the following error.
JavaScript
1
8
1
Compilation Error in model stg_news_sentiment_analysis_incr
2
(models/staging/stg_news_sentiment_analysis_incr.sql)
3
'audit_tbl_insert' is undefined in macro run_hooks (macros/materializations/hooks.sql)
4
called by macro materialization_table_default (macros/materializations/models/table/table.sql) called by model stg_news_sentiment_analysis_incr
5
(models/staging/stg_news_sentiment_analysis_incr.sql).
6
This can happen when calling a macro that does not exist.
7
Check for typos and/or install package dependencies with "dbt deps".
8
Advertisement
Answer
Your macro’s definition has too much whitespace in the braces that define the jinja block:
JavaScript
1
2
1
{ % macro audit_tbl_insert (model_id_no, model_name_txt) % }
2
Needs to be
JavaScript
1
2
1
{% macro audit_tbl_insert (model_id_no, model_name_txt) %}
2
And then this should work just fine.