You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Airflow:Jinja模板中设置ds为prev_execution_date_success默认值失效求助

Airflow Jinja模板中prev_execution_date_success默认值失效的解决方法

在Airflow DAG的Jinja模板场景中,用default过滤器给prev_execution_date_success设置默认值ds时,会遇到问题:当prev_execution_date_success为None时,默认值ds不生效,结果仍返回None。

这是因为Jinja的default过滤器默认仅对未定义的变量生效,而prev_execution_date_success属于已定义但值为None的变量,所以不会触发默认逻辑。

解决方案1:添加boolean=True参数

修改模板中的过滤器,加入boolean=True参数,让过滤器在变量为假值(包括None、空字符串等)时都返回默认值:

script_args = { '--previousRunDt': '{{ prev_execution_date_success | default(ds, boolean=True) }}' }

解决方案2:显式条件判断

也可以用直观的条件判断实现相同效果:

script_args = { '--previousRunDt': '{{ prev_execution_date_success if prev_execution_date_success is not none else ds }}' }

内容的提问来源于stack exchange,提问作者Gokul S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 09:52:13