Repository navigation
Description
Under which category would you file this issue?
Providers
Apache Airflow version
3.3.2
What happened and how to reproduce it?
With deferrable=True, wait_until_job_complete=True and get_logs=True, a Job whose container exits non-zero fails the task with Job failed with error: BackoffLimitExceeded. The task log contains none of the container's output, so the cause of the failure isn't visible in Airflow.
In KubernetesJobOperator.execute_complete, the error check raises before the log-writing block runs:
try:
ti = context["ti"]
ti.xcom_push(key="job", value=event["job"])
if event["status"] == "error":
raise AirflowException(event["message"]) # raised here on failure
if self.get_logs: # so this never runs for a failed Job
for pod_name in event.get("pod_names") or []:
...
self._write_logs(pods_by_name[pod_name])
...
finally:
self._cleanup_monitoring_pods_from_dict(...) # then deletes the pod (on_finish_action=delete_pod)Logs are written only when the Job succeeds. When it fails, on_finish_action="delete_pod" deletes the pod in the finally block, so its output can't be read afterwards either.
A second, related gap: pod_names holds only the pods found when the task deferred. Pods the Job controller creates later for backoffLimit retries are never logged or cleaned up.
To reproduce:
KubernetesJobOperator(
task_id="fail",
image="busybox",
cmds=["sh", "-c", "echo 'the real error'; exit 1"],
backoff_limit=1,
wait_until_job_complete=True,
deferrable=True,
get_logs=True,
)The task fails with BackoffLimitExceeded, and the real error doesn't appear in the task log.
What you think should happen instead?
When get_logs=True, write the pod logs before raising on status == "error", and include every pod that belongs to the Job. For example, look them up by the batch.kubernetes.io/job-name=<job> label rather than only the pods in event["pod_names"]. A failure while reading logs should be logged as a warning and should not replace the Job's own error.
Operating System
Debian (Astro Runtime image)
Deployment
Astronomer
Apache Airflow Provider(s)
cncf-kubernetes
Versions of Apache Airflow Providers
apache-airflow-providers-cncf-kubernetes==10.23.0 (the code is unchanged in 10.25.0 and on main)
Official Helm Chart version
Not Applicable
Kubernetes Version
v1.35.8 (EKS)
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
This happens every time a Job fails. Issue #42144 also covered deferred-mode log retrieval, but for a different cause (pod_name was None in the event), and it was closed as stale. We work around this one by overriding execute_complete in a subclass to write the logs of all the Job's pods before calling super().
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Nov 2, 2026
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.