Skip to content

Pydantic ValidationError when rerunning a dagrun #61381

Closed

Description

@DonHaul

Apache Airflow version

Other Airflow 3 version (please specify below)

If "Other Airflow 3 version" selected, which one?

3.1.5

What happened?

I tried to clear dag and rerun dags that had run in 3.0.6 and I got the following error:
airflow db clear -t dag_runs ...

Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/jobs/scheduler_job_runner.py", line 1079, in _execute
    self._run_scheduler_loop()
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/jobs/scheduler_job_runner.py", line 1369, in _run_scheduler_loop
    num_queued_tis = self._do_scheduling(session)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/jobs/scheduler_job_runner.py", line 1479, in _do_scheduling
    callback_tuples = self._schedule_all_dag_runs(guard, dag_runs, session)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/utils/retries.py", line 97, in wrapped_function
    for attempt in run_with_db_retries(max_retries=retries, logger=logger, **retry_kwargs):
  File "/home/airflow/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 445, in __iter__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 378, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 400, in <lambda>
    self._add_action_func(lambda rs: rs.outcome.result())
                                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/python/lib/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/python/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/utils/retries.py", line 106, in wrapped_function
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/jobs/scheduler_job_runner.py", line 1921, in _schedule_all_dag_runs
    callback_tuples = [(run, self._schedule_dag_run(run, session=session)) for run in dag_runs]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/jobs/scheduler_job_runner.py", line 1921, in <listcomp>
    callback_tuples = [(run, self._schedule_dag_run(run, session=session)) for run in dag_runs]
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/jobs/scheduler_job_runner.py", line 2037, in _schedule_dag_run
    schedulable_tis, callback_to_run = dag_run.update_state(session=session, execute_callbacks=False)
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/utils/session.py", line 98, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/airflow/models/dagrun.py", line 1184, in update_state
    context_from_server=DagRunContext(
                        ^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.11/site-packages/pydantic/main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for DagRunContext
dag_run.start_date
  Input should be a valid datetime [type=datetime_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.12/v/datetime_type

What you think should happen instead?

Dags should be allowed to be restarted withouth any issues

How to reproduce

Have dags that had previously run in 3.0.6 .
Upgrade to 3.1.5
Do a call to the clear dag run api

Error will appear

Operating System

Debian GNU/Linux 12 (bookworm)

Versions of Apache Airflow Providers

No response

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Feb 3, 2026
  2. DonHaul commented on Feb 3, 2026

    @DonHaul
    ContributorAuthor

    using airflow db clear to remove older dag runs worked as a temporary fix

  3. v4xsh commented on Feb 4, 2026

    @v4xsh

    I’d like to take ownership of this issue and work on a fix.

    From the traceback, this appears to be a regression tied to stricter Pydantic v2 validation introduced in Airflow 3.1.5. The DagRunContext model expects dag_run.start_date to be a valid datetime, but DAG runs (especially those cleared or migrated from legacy versions like 3.0.6) can legitimately have start_date=None in the database. When the scheduler attempts to construct the context for these runs, it triggers a ValidationError.

    This seems to be a backward-compatibility gap in the core scheduling logic rather than a user configuration error.

    Proposed Approach:

    • Model Update: Evaluate if start_date in DagRunContext should be changed to Optional[datetime] to accommodate cleared states.
    • Logic Safeguard: Alternatively, implement a safe default or data-filling mechanism in scheduler_job_runner.py before the model is instantiated during reruns.
    • Regression Testing: Add a test case to simulate clearing a legacy DAG run and ensuring the scheduler loop completes without a ValidationError.

    I can try to reproduce this locally on my environment and am ready to implement the fix once there is a consensus on the preferred path. I would appreciate being assigned to this issue.

  4. gyli commented on Feb 13, 2026

    @gyli
    Collaborator

    Thanks @v4xsh, issue is assigned to you

  5. removed
    needs-triage
    on Feb 13, 2026
  6. v4xsh commented on Feb 16, 2026

    @v4xsh

    Hi @gyli,

    Thank you for assigning this to me — I really appreciate it.

    Apologies for the slight delay, I was busy last week with exams. I’ll start working on it now.

  7. v4xsh commented on Feb 16, 2026

    @v4xsh

    Hi @gyli,

    I’ve opened a PR to address this issue:

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

    The fix updates the DagRun Pydantic model to allow start_date=None, which aligns it with the database/ORM behavior for cleared and queued runs. I’ve also added unit tests to cover both:

    • Direct DagRun validation with start_date=None
    • DagRunContext construction used by the scheduler

    Please let me know if any adjustments are needed.

    Thanks!

  8. potiuk commented on Mar 2, 2026

    @potiuk
    Member

    @v4xsh We are unassigning you from this issue as part of our updated assignment policy.

    This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.

    We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.

  9. v4xsh commented on Mar 2, 2026

    @v4xsh

    Hi @potiuk — thanks for the clarification.
    I’m actively working on this and have already opened PR #61981.
    Happy to make any changes needed.

  10. DonHaul commented on Apr 9, 2026

    @DonHaul
    ContributorAuthor

    Closing as it seems to have been solved in: #58175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:schedulerkind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions