Fix TypeError in TaskInstance.next_retry_datetime() for None end_date#70092
Open
AdityaBhattacharya1 wants to merge 5 commits into
Open
Fix TypeError in TaskInstance.next_retry_datetime() for None end_date#70092AdityaBhattacharya1 wants to merge 5 commits into
AdityaBhattacharya1 wants to merge 5 commits into
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
yuseok89
reviewed
Jul 20, 2026
| if self.task.max_retry_delay: | ||
| delay = min(self.task.max_retry_delay, delay) | ||
| return self.end_date + delay | ||
| base = self.end_date if self.end_date is not None else timezone.utcnow() |
Contributor
There was a problem hiding this comment.
Nice catch on the TypeError.
I might be missing something, but since this is recomputed each scheduler pass, wouldn't an end_date is None TI always land at utcnow() + delay and stay up_for_retry indefinitely? Curious what you think.
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.
A task instance can end up in the
up_for_retrystate withend_dateleft asNone, for example if the process running it is killed abruptly before the end date gets recorded, or via any code path that transitions task state without going throughTaskInstance.set_state(). When that happens,next_retry_datetime()unconditionally computesself.end_date + delay, raising:This is called from
NotInRetryPeriodDep._get_dep_statuses(), which the scheduler invokes on every scheduling pass for a retry-eligible task. The exception is unhandled at that call site, so depending on version this either crashes the scheduler process outright, or (after the per-DagRun failure isolation added in #62893) gets caught and logged but causes that DagRun's scheduling pass to fail identically every time it's re-evaluated — the affected task instance never recovers on its own without directly patching itsend_datein the metadata database.Personally I faced this error for a DAG run where a DAG had been transitioned to
up_for_retrystatus and then paused. Later revision of the DAG changed the DAG structurally. When I unpaused the DAG and cleared state for the previous DAG run, the end_date was never repopulated for that task instance: DagRun.verify_integrity() / expand_mapped_task() had to reconcile the stale map_index=-1 row against a task definition that had since become mapped, and that reconciliation left the row up_for_retry with end_date still NULL.Also added a unit test on
next_retry_datetime()covering theend_date=Nonecase directly, and one onNotInRetryPeriodDepreproducing the actual crash path named in the linked issues (state=up_for_retry,end_date=None) to confirm the dependency check no longer raises.closes: #51640
related: #19615
Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.