ayanhussain81 opened a new pull request, #74374:
URL: https://github.com/apache/airflow/pull/74374
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
`_schedule_all_dag_runs` catches per-run scheduling errors so one bad DAG
run cannot stop the
others. The `except` block logs with `run.run_id` and `run.dag_id`, read
from the same object that
just failed. If the scheduling call detached that run from the session, the
read raises
`DetachedInstanceError` from inside the handler. The handler does not catch
it, so the exception
escapes `_schedule_all_dag_runs` and the scheduler process exits.
This is the failure mode reported in #73311, where the crash is reached via
`TaskMap.expand_mapped_task`. The handler itself can also raise, which turns
any detached-run error
into a scheduler crash.
This change reads `run_id` and `dag_id` before the `try` block, while the
run is still attached,
and logs those values in the handler. Nothing else changes.
Regression test:
`test_schedule_all_dag_runs_error_handler_survives_detached_dag_run` detaches
the
run inside `_schedule_dag_run`, then asserts `_schedule_all_dag_runs`
returns normally. It fails on
`main` with `DetachedInstanceError` escaping the handler, and passes with
this change.
Not verified: the existing
`test_schedule_all_dag_runs_does_not_crash_on_single_dag_run_error`, which
covers the same loop, could not run in the local sandbox because of a
`ModuleNotFoundError: airflow_shared`
in a logging-capture fixture. CI will run it. `ruff check` and `ruff format
--check` are clean. Breeze
and mypy were not run locally.
Related: #73311 (open, no linked PR). This PR does not fix the underlying
session-expiry in
`expand_mapped_task`; it only stops the handler from turning that error into
a crash.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
<!--
Generated-by: Claude Code following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
Claude Code was used to read the issue and code, reproduce the failure with
a test, implement the
change, and run the tests and linters. The diff and results were reviewed
before submission.
---
* Read the [Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines).
* Relates to #73311.
* Newsfragment (`{pr_number}.bugfix.rst`) will be added as a follow-up
commit once the PR number is known.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]