You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "DonHaul (via GitHub)" <gi...@apache.org> on 2026/02/03 08:35:11 UTC

[I] Pydantic ValidationError when rerunning a dagrun [airflow]

DonHaul opened a new issue, #61381:
URL: https://github.com/apache/airflow/issues/61381

   ### 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:
   ```2026-02-02T21:05:10.775516Z [error    ] Exception when executing SchedulerJob._run_scheduler_loop [airflow.jobs.scheduler_job_runner.SchedulerJobRunner] loc=scheduler_job_runner.py:1083
   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](https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html#operation/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
   
   - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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: commits-unsubscribe@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "DonHaul (via GitHub)" <gi...@apache.org>.
DonHaul closed issue #61381: Pydantic ValidationError when rerunning a dagrun
URL: https://github.com/apache/airflow/issues/61381


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "DonHaul (via GitHub)" <gi...@apache.org>.
DonHaul commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3840449933

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


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "v4xsh (via GitHub)" <gi...@apache.org>.
v4xsh commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3986579943

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


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "DonHaul (via GitHub)" <gi...@apache.org>.
DonHaul commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-4212755987

   Closing as it seems to have been solved in: https://github.com/apache/airflow/pull/58175


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "v4xsh (via GitHub)" <gi...@apache.org>.
v4xsh commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3847355963

   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.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "v4xsh (via GitHub)" <gi...@apache.org>.
v4xsh commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3906472649

   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.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3986406026

   @v4xsh We are unassigning you from this issue as part of our updated [assignment policy](https://github.com/apache/airflow/blob/main/contributing-docs/04_how_to_contribute.rst#contribute-code-changes).
   
   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.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "gyli (via GitHub)" <gi...@apache.org>.
gyli commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3898485094

   Thanks @v4xsh, issue is assigned to you


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Pydantic ValidationError when rerunning a dagrun [airflow]

Posted by "v4xsh (via GitHub)" <gi...@apache.org>.
v4xsh commented on issue #61381:
URL: https://github.com/apache/airflow/issues/61381#issuecomment-3907509526

   
   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!
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org