A dbt_project.yml model pre-hook is failing to render macros. The following implementation:
# gold/dbt_project.yml
config-version: 2
...
models:
gold:
+pre-hooks: "{{ incremental_failsafe() }}"
And the following macro:
-- gold/macros/utils/incremental_failsafe.sql
{% macro incremental_failsafe() %}
{# /*
Used to wrap AND clauses that should only be run on dev/CI dbt runs.
For example, to limit the number of records scanned on an incremental
table. This macro will return True unless the target profile is 'prod':
`dbt run --target prod`
*/ #}
{% if target.name == "prod" %}
{% set incremental_failsafe = False %}
{% else %}
{% set incremental_failsafe = True %}
{% endif %}
{{ log("Running with incremental_failsafe: " ~ incremental_failsafe, info=True) }}
{{ return(incremental_failsafe) }}
{% endmacro %}
Results in the following:
(snowflake) Teghans-MacBook-Pro:gold tnightengale$ dbt compile
Running with dbt=0.17.2
Encountered an error:
Compilation Error
Could not render {{ incremental_failsafe() }}: 'incremental_failsafe' is undefined
I know there was an issue with dbt 0.17.0 around pre-hooks as outlined in this slack exchange. I've tried using both +pre-hook: and pre-hook: specs in the yml as suggested in that conversation to no avail, despite the fact that I am running 0.17.2 (not 0.17.0). Any insight would be welcome!
EDIT: Solution
Truthfully, the answer is so dumb and obvious: the error resulted from having +pre-hooks: as opposed to +pre-hook:. However the suggested answer caused me to take a second look. I am marking it as correct because it gives a lot of helpful context on hooks in general. Cheers!