Skip to content

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

Closed
v4xsh wants to merge 1 commit into
apache:mainfrom
v4xsh:fix-61381-null-start-date-dagruncontext
Closed

v4xsh wants to merge 1 commit into
apache:mainfrom
v4xsh:fix-61381-null-start-date-dagruncontext

Conversation

@v4xsh

@v4xsh v4xsh commented Feb 16, 2026

Copy link
Copy Markdown

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.
@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:task-sdk labels Feb 16, 2026

@yuseok89 yuseok89 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR's changes already appear to be on current main (#58175).
If this duplicates that work, this PR can probably be closed.

@potiuk potiuk closed this Apr 2, 2026
@potiuk

potiuk commented Apr 2, 2026

Copy link
Copy Markdown
Member

Closing

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

3 participants