Skip to content

Allow null start_date in DagRun Pydantic model to fix rerun regression (#61381)#61981

Open
v4xsh wants to merge 1 commit intoapache:mainfrom
v4xsh:fix-61381-null-start-date-dagruncontext
Open

Allow null start_date in DagRun Pydantic model to fix rerun regression (#61381)#61981
v4xsh wants to merge 1 commit intoapache:mainfrom
v4xsh:fix-61381-null-start-date-dagruncontext

Conversation

@v4xsh
Copy link

@v4xsh v4xsh commented Feb 16, 2026

Fix Pydantic ValidationError when rerunning cleared DagRun

Closes #61381


Problem

When rerunning or clearing DAG runs (especially those created in older Airflow versions), the scheduler may raise:

ValidationError: dag_run.start_date
Input should be a valid datetime

This occurs because the Pydantic DagRun model required start_date to be a non-null datetime, while cleared or queued DAG runs can legitimately have start_date=None in the database.


Root Cause

The Pydantic DagRun model in:

airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py

did not allow start_date=None, causing a ValidationError when constructing DagRunContext during scheduling.


Changes Made

1️⃣ Allow start_date to be nullable

- start_date: UtcDateTime
+ start_date: UtcDateTime | None = None

This aligns the Pydantic model with:

  • ORM definition
  • Database state
  • Scheduler behavior

2️⃣ Add default for partition_key

- partition_key: str | None
+ partition_key: str | None = None

Ensures consistent optional behavior.


Tests Added

New test file:

airflow-core/tests/unit/api_fastapi/execution_api/datamodels/test_taskinstance.py

Includes:

  • test_dagrun_model_accepts_null_start_date
  • test_dagrun_context_accepts_null_start_date

These verify:

  • The Pydantic DagRun model accepts start_date=None
  • DagRunContext can be constructed without raising ValidationError

Result

  • Scheduler no longer crashes when rerunning cleared DAG runs
  • Backward compatibility with existing DAG runs is restored
  • Model validation now reflects actual database behavior

Allow DagRun.start_date to be optional to support cleared and legacy DagRuns.
Add regression tests to ensure scheduler accepts NULL start_date.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pydantic ValidationError when rerunning a dagrun

1 participant