i am facing some issues when trying to load a partitioned table using the incremental mode. Each partition is created based on a execution_date variable i pass as an argument. For some reasons, the new partition is always generated using CurrentDate as the partition value. Even tough the variable passed as argument as a different date value. I have defined a macro to format the variable passed through the command line. Please find below the code for the macro:
{% macro formatted_date(execution_date) %}
{% set execution_date_obj = modules.datetime.datetime.strptime(execution_date|string, "%Y%m%d") %}
{{ return(execution_date_obj.strftime("%Y-%m-%d")) }}
{% endmacro %}
And below is how I have defined the dbt model for loading the table:
{{config(alias='unipr_salesforce',
materialized = 'incremental',
partitions = [formatted_date(var('execution_date'))]
)}}
Finally, this is the command use to run the dbt model, where you can see the variable used as argument:
unipr-subscription-pipeline toledanof$ dbt run --target dev --profiles-dir ./ --vars 'execution_date : "20210310"'
Every time i run the dbt model, the partition generated correspond to the CurrentDate, regardless the execution_date value. Does anybody know a possible reason for this behaviour? Thank you !