Fix KubernetesJobOperator failing when pods are deleted after job completion#63569
Merged
jscheffl merged 2 commits intoapache:mainfrom Mar 14, 2026
Merged
Conversation
…pletion Handle 404 ApiException in execute_complete to skip log retrieval gracefully instead of failing the task when pods are cleaned up before Airflow fetches logs.
XD-DENG
reviewed
Mar 13, 2026
Member
XD-DENG
left a comment
There was a problem hiding this comment.
Nit on test coverage: Could you add a test case with multiple pods (e.g., pod_names=["pod-1", "pod-2"]) where get_pod returns a 404 for one pod but succeeds for the other? This would exercise the continue behavior in the loop and confirm that logs are still written for surviving pods while the deleted one is skipped. That's the more realistic scenario for jobs with parallelism > 1.
Contributor
Author
|
Added a multi-pod test with two pods where one returns 404 and the other succeeds. It verifies that the loop continues past the deleted pod and still writes logs for the surviving one. |
jscheffl
approved these changes
Mar 14, 2026
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.
When a Kubernetes Job completes but the pod is deleted before Airflow fetches logs (e.g., by cluster autoscaler),
execute_completefails with an unhandledApiException(404). Task retries also fail repeatedly since they re-enterexecute_completeand hit the same error.This fix catches the 404 and skips log retrieval for deleted pods, resolving both the initial failure and the retry loop.
Note: whether retries of deferred tasks should re-run
executeinstead ofexecute_completeis a broader SDK-level concern and out of scope here.closes: #56693
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines