You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deferred TI's next_method and next_kwargs not cleared on retries #18146
If your first try fails and you have retries enabled, the subsequent tries skip right to the final next_method(**next_kwargs) instead of starting with execute again.
What you expected to happen
Like we reset things like start date, we should wipe next_method and next_kwargs so we can retry the task from the beginning.
changed the title [-]Deferrable operator not clearing `next_method` and `next_kwargs` on retries[/-][+]Deferred TI's `next_method` and `next_kwargs` not cleared on retries[/+]on Sep 10, 2021
The following DAG can be used to both reproduce (dagruns fail) and verify the issue is fixed (dagruns succeed). Basically, the first run it will fail so it ends up in UP_FOR_RETRY and will succeed on the second try.
fromdatetimeimportdatetime, timedeltafromairflowimportDAGfromairflow.exceptionsimportAirflowExceptionfromairflow.modelsimportBaseOperatorfromairflow.triggers.testingimportSuccessTriggerclassRetryOperator(BaseOperator):
defexecute(self, context):
ti=context["ti"]
has_next_method=bool(ti.next_method)
try_number=ti.try_numberself.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},
)
defnext(self, context, execute_try_number, event=None):
self.log.info("In next!")
ti=context["ti"]
has_next_method=bool(ti.next_method)
try_number=ti.try_numberself.log.info(
f"In `next`: has_next_method: {has_next_method}, try_number:{try_number}, excute_try_number: {execute_try_number}"
)
iftry_number==1:
# Force a retryraiseAirflowException("Force a retry")
# Did we run `execute`?ifexecute_try_number!=try_number:
raiseAirflowException("`execute` wasn't run during retry!")
returnNone# Success!withDAG(
"triggerer_retry", schedule_interval=None, start_date=datetime(2021, 9, 13)
) asdag:
RetryOperator(task_id="retry", retries=1, retry_delay=timedelta(seconds=15))
Activity
[-]Deferrable operator not clearing `next_method` and `next_kwargs` on retries[/-][+]Deferred TI's `next_method` and `next_kwargs` not cleared on retries[/+]Wipe next_kwargs and next_method on task failure
BugFix: Wipe ``next_kwargs`` and ``next_method`` on task failure (#18210
jedcunningham commentedon Sep 13, 2021
The following DAG can be used to both reproduce (dagruns fail) and verify the issue is fixed (dagruns succeed). Basically, the first run it will fail so it ends up in UP_FOR_RETRY and will succeed on the second try.