YoannAbriel opened a new pull request, #62853:
URL: https://github.com/apache/airflow/pull/62853

   # fix: clear next_method and next_kwargs on task retry
   
   ## Problem
   
   When a deferrable operator fails during trigger resumption and enters retry, 
`next_method` and `next_kwargs` are not cleared in Airflow 3.x. This means the 
retry attempt skips `execute()` entirely and jumps straight to the stale 
`next_method(**next_kwargs)` callback from the previous attempt.
   
   This causes two failure modes:
   1. The task processes "zombie" trigger events from the previous attempt
   2. The task fails because initial setup logic in `execute()` was bypassed
   
   This was a known issue in Airflow 2.x, fixed in #18146 / #18210 by 
nullifying `next_method` and `next_kwargs` on retry. With the transition to the 
Task SDK and Internal API in 3.x, the reset logic was not carried over to the 
new `prepare_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 to 
`clear_next_method_args()`, so the deferred execution state persisted across 
retries.
   
   ## Fix
   
   Added `self.clear_next_method_args()` in `prepare_db_for_next_try()`, right 
before the new attempt UUID is generated. This ensures the retry always starts 
fresh from `execute()`.
   
   One line change in `airflow-core/src/airflow/models/taskinstance.py`, plus 
two tests:
   - `test_prepare_db_for_next_try_clears_next_method` — verifies 
`prepare_db_for_next_try()` resets deferred fields
   - `test_handle_failure_clears_next_method_on_retry` — verifies the full 
`handle_failure()` path clears deferred state when retries remain
   
   All 216 model tests + 127 execution API tests pass.
   
   Closes: #62845
   
   ##### Was generative AI tooling used to co-author this PR?
   - [X] Yes — 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]

Reply via email to