Our dbt_project.yml file, config-version: 1 has two variables across different incremental models, for which one we use a macro called today()
vars:
start_date: '{{ today(offset_days=-1) }}'
end_date: '2999-12-31'
When testing the migration to dbt 0.17.2, config-version:2, we face the following issue
Running with dbt=0.17.2
Encountered an error:
Compilation Error
Could not render {{ today(offset_days=-1) }}: 'today' is undefined
The macro we built it end of last year. I believe dbt changed the way macro variables are referenced, however not sure how to tackle this.
-- returns current hour in YYYY-MM-DD-HH format,
-- optionally offset by N days (-N or +N) or M hours (-M or +M)
{%- macro current_hour(offset_days=0, offset_hours=0) -%}
{%- set now = modules.datetime.datetime.now(modules.pytz.utc) -%}
{%- set dt = now + modules.datetime.timedelta(days=offset_days, hours=offset_hours) -%}
{{- dt.strftime("%Y-%m-%d-%H") -}}
{%- endmacro -%}
-- returns current day in YYYY-MM-DD format,
-- optionally offset by N days (-N or +N) or M hours (-M or +M)
{%- macro today(offset_days=0, offset_hours=0) -%}
{{- current_hour(offset_days, offset_hours)[0:10] -}}
{%- endmacro -%}
-- accepts a timestamp string and returns a timestamo string
-- formatted like 'YYYY-MM-DD HH24:MI:SS.US', e.g. '2019-11-02 06:11:42.690000'
{%- macro dt_to_utc(ts_string) -%}
TO_CHAR({{ ts_string }}::TIMESTAMPTZ, 'YYYY-MM-DD HH24:MI:SS.US')
{%- endmacro -%}