You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ronak-sirwani (via GitHub)" <gi...@apache.org> on 2026/03/04 05:24:16 UTC
[I] Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x [airflow]
ronak-sirwani opened a new issue, #62845:
URL: https://github.com/apache/airflow/issues/62845
### Apache Airflow version
Other Airflow 3 version (please specify below)
### If "Other Airflow 3 version" selected, which one?
3.0.6
### What happened?
When a Deferrable Operator fails during a trigger resumption and enters a Retry (following an Up For Retry state), the subsequent attempt incorrectly persists the next_method and next_kwargs from the previous failed attempt.
Instead of starting fresh with the standard execute() entry point, the Worker attempts to immediately resume the task using the stale next_method(**next_kwargs) data. This causes the task to either process "stale/zombie" events from the previous attempt or fail prematurely because the initial setup logic in execute() was bypassed.
- Airflow 2.x: This looks like a known issue addressed in https://github.com/apache/airflow/issues/18146. The fix ensured that when a task was reset for a retry, the next_method and next_kwargs columns in taskinstance table were explicitly nullified.
Airflow 3.x: With the transition to the new Internal API and Task SDK (e.g., Issue https://github.com/apache/airflow/issues/47373), this reset logic appears to be missing and subsequent attempts skip execute() entirely.
### What you think should happen instead?
Taskinstance attributes like next_method and next_kwargs should get reset on retry, so we can retry the task from the beginning.
### How to reproduce
```python
from datetime import datetime, timedelta
from airflow import DAG
from airflow.exceptions import AirflowException
from airflow.sdk import BaseOperator
from airflow.triggers.testing import SuccessTrigger
class RetryOperator(BaseOperator):
def execute(self, context):
ti = context["ti"]
has_next_method = bool(ti._ti_context_from_server.next_method)
try_number = ti.try_number
self.log.info(
f"In `execute`: has_next_method: {has_next_method}, try_number:{try_number}"
)
self.defer(
trigger=SuccessTrigger(),
method_name="next",
kwargs={"execute_try_number": try_number},
)
def next(self, context, execute_try_number, event=None):
self.log.info("In next!")
ti = context["ti"]
has_next_method = bool(ti._ti_context_from_server.next_method)
try_number = ti.try_number
self.log.info(
f"In `next`: has_next_method: {has_next_method}, try_number:{try_number}, excute_try_number: {execute_try_number}"
)
if try_number == 1:
# Force a retry
raise AirflowException("Force a retry")
# Did we run `execute`?
if execute_try_number != try_number:
raise AirflowException("`execute` wasn't run during retry!")
return None # Success!
with DAG(
"triggerer_retry", schedule_interval=None, start_date=datetime(2021, 9, 13)
) as dag:
RetryOperator(task_id="retry", retries=1, retry_delay=timedelta(seconds=15))
```
### Operating System
Linux
### Versions of Apache Airflow Providers
_No response_
### Deployment
Other Docker-based deployment
### Deployment details
_No response_
### Anything else?
#### Temporary workaround:
To mitigate this in my custom operators, I’ve had to implement a "Single-Entry" pattern to force idempotency:
Always setting method_name="execute" in the self.defer() call.
Passing a unique attempt_id (from ti.try_number) into the Trigger.
Manually validating the attempt_id inside execute() to detect if the event is fresh or stale.
While this works, it adds significant boilerplate and complexity to every custom operator.
### Are you willing to submit PR?
- [x] 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] Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x [airflow]
Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on issue #62845:
URL: https://github.com/apache/airflow/issues/62845#issuecomment-3999294646
I am unable to reproduce the issue in main. The dag has `schedule_interval` which is not valid. Upon fixing it I can see the first run printing the log in execute method with `next_method` and `next_kwargs` in the db on deferring. Once the task fails and is set to retry the values are cleared and the next retry again executes again to print "[2026-03-04 23:37:03] INFO - In `next`: has_next_method: True, try_number:2, excute_try_number: 2".
This was reported in #56704 and the fix was backported in https://github.com/apache/airflow/commit/53c05a0e80c581c24ecbfb7f9c3a4dc35d70fd2d to be released in 3.1.5. Can you please try the latest version of Airflow to see if the issue still exists?
--
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] Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x [airflow]
Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on issue #62845:
URL: https://github.com/apache/airflow/issues/62845#issuecomment-4002093972
No worries. Thanks for the confirmation @ronak-sirwani .
--
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] Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on issue #62845:
URL: https://github.com/apache/airflow/issues/62845#issuecomment-3995384436
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
--
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] Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x [airflow]
Posted by "ronak-sirwani (via GitHub)" <gi...@apache.org>.
ronak-sirwani commented on issue #62845:
URL: https://github.com/apache/airflow/issues/62845#issuecomment-4001912739
Thanks for taking a look.
- The dag has schedule_interval which is not valid >>> i mistakenly added this here (there should be schedule=None, edited in the description), in my dag is was that only.
After testing again with latest version of airflow (3.1.7), the issue seems resolved. The confusion happened because of local environment mix-up on my side, and one of them had airflow 3.1.0, while 3.1.6 was also present, i mistakenly assumed i was testing against the newer version.
Apologies for the confusion.
--
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] Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x [airflow]
Posted by "ronak-sirwani (via GitHub)" <gi...@apache.org>.
ronak-sirwani closed issue #62845: Deferred TI's next_method and next_kwargs not cleared on retries in airflow 3.x
URL: https://github.com/apache/airflow/issues/62845
--
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