Repository navigation
Fix DetachedInstanceError crash in mapped task expansion - #73451
anmolxlight wants to merge 2 commits into
Conversation
Read the Dag run trace carrier while still bound to the session and stop the scheduling error handler from touching detached attributes. Closes: apache#73311 Signed-off-by: anmolxlight <anmolxlight@gmail.com>
fca7653 to
283db01
Compare
|
Hello @anmolxlight - thank you for your contributions to Apache Airflow! The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 10 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are. What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack. Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst. Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting |
Closes: #73311
Root cause: in
TaskMap.expand_mapped_task, the Dag run is obtained via a lazy relationship (unmapped_ti.dag_run) or a scalar fetch, butcontext_carrieris only read much later after flushes, queries, and mutation hooks. By then session commits elsewhere in the scheduling chain can have expired and detached the Dag run, so the late attribute access raisesDetachedInstanceError. The scheduling error handler then touches detachedrun.run_id/run.dag_id, raising a secondDetachedInstanceErrorthat escapes and kills the scheduler.Fix:
new_task_run_carrier. A plain dict local is immune to later expire/detach, with zero extra queries.run_id/dag_idinto locals before the try block in_schedule_all_dag_runsso the error handler can never throw.Verification: new logic proven with a standalone SQLAlchemy repro (old access pattern raises, captured local survives commit plus detach);
test_taskmap.pygreen via breeze (3 passed); mypy, ruff, ruff-format green.