v4xsh opened a new pull request, #61981:
URL: https://github.com/apache/airflow/pull/61981

   
   ##  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
   
   ```diff
   - 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`
   
   ```diff
   - 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
   
   ---
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to