首页 > 解决方案 > 示例 dag 尝试将 execution_date 参数保存为 null

问题描述

从气流 2.0.1 升级到 2.1.0 后我有一个问题。当我运行示例 dag 并且失败时,我无法在task_fail表中保存一行。

ERROR: null value in column "execution_date" violates not-null constraint

from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator
from test_methods import test_python_method, test_python_log

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5)
}

with DAG(
    'Sample-Dag',
    default_args=default_args,
    start_date= datetime(2021, 1, 1),
    schedule_interval=timedelta(minutes=10),
    catchup=False,
) as dag:

    task_1 = PythonOperator(
        task_id='Task-1',
        python_callable=test_python_method,
    )

    task_2 = PythonOperator(
        task_id='Task-2',
        python_callable=test_python_log,
    )

    task_1 >> task_2

如果有帮助,我可以添加配置,但这可能是因为 Dag 结构。

标签: python-3.xairflow

解决方案


我想你可能没有这样做airflow db upgrade

在迁移到较新的 Airflow 版本后,您始终必须运行它。


推荐阅读