Airflow Error : strptime() argument must be str, not Proxy

Airflow Error : strptime() argument must be str, not Proxy

在 Airflow 中,我们使用 airflow 宏 'next_ds' 进行一些日期计算:

{{ macro.ds_add(next_ds,-1) }}

然而,在 airflow 升级到 2.2.2 后,next_ds 从日期更改为 Proxy。

我们在自定义函数中尝试了以下但出现错误:

datetime.strptime(ds,'%Y-%m-%d')

错误: 类型错误:strptime() 参数必须是 str,而不是 Proxy。

根据https://github.com/apache/airflow/pull/19592升级是最优解。 有没有其他方法可以计算下一个执行日期?

一种模仿 next_ds 行为的方法:

导入 croniter 包并定义您自己的计划,它使用与 airflow cron 相同的语法:

import croniter
schedule = '0 6 * * sat'   

# Custom function
def next_exec_date(dt,days_delta):
    cron = croniter.croniter(schedule, dt)
    return cron.get_next(datetime) + timedelta(days=days_delta) 

#Also, define below in dag_args :
# 'user_defined_macros': {
#     'custom_next_exec_date': next_exec_date,
# }

现在,像 next_ds 一样使用下面的宏:

( custom_next_exec_date(ds,-1)

干杯!!