fix: clear next_method and next_kwargs on task retry - #62853
Closed
YoannAbriel wants to merge 1 commit into
Closed
Conversation
When a deferred task fails and is eligible for retry, the next_method and next_kwargs fields must be cleared so the retry starts fresh from execute() rather than resuming from the stale deferral callback. While the execution API route already clears these fields via a Core UPDATE query, adding the clearing to prepare_db_for_next_try() provides a defensive guarantee that any code path preparing a TI for retry will properly reset the deferral state. Closes: apache#62845
YoannAbriel
force-pushed
the
fix/issue-62845
branch
from
March 5, 2026 11:02
cbf020e to
eb17081
Compare
Contributor
|
As confirmed by the user this is resolved as of Airflow 3.1.7. I am closing this PR. Please feel free to reopen if this can be reproduced. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: clear next_method and next_kwargs on task retry
Problem
When a deferrable operator fails during trigger resumption and enters retry,
next_methodandnext_kwargsare not cleared in Airflow 3.x. This means the retry attempt skipsexecute()entirely and jumps straight to the stalenext_method(**next_kwargs)callback from the previous attempt.This causes two failure modes:
execute()was bypassedThis was a known issue in Airflow 2.x, fixed in #18146 / #18210 by nullifying
next_methodandnext_kwargson retry. With the transition to the Task SDK and Internal API in 3.x, the reset logic was not carried over to the newprepare_db_for_next_try()method.Root Cause
TaskInstance.prepare_db_for_next_try()is the central method in 3.x for preparing a TI for its next attempt (generating new UUID, incrementing try_number, resetting state). It was missing a call toclear_next_method_args(), so the deferred execution state persisted across retries.Fix
Added
self.clear_next_method_args()inprepare_db_for_next_try(), right before the new attempt UUID is generated. This ensures the retry always starts fresh fromexecute().One line change in
airflow-core/src/airflow/models/taskinstance.py, plus two tests:test_prepare_db_for_next_try_clears_next_method— verifiesprepare_db_for_next_try()resets deferred fieldstest_handle_failure_clears_next_method_on_retry— verifies the fullhandle_failure()path clears deferred state when retries remainAll 216 model tests + 127 execution API tests pass.
Closes: #62845
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.