From 72a4d5be9826be216a9cfd07b83a91b8b42a93e3 Mon Sep 17 00:00:00 2001 From: Amogh Desai Date: Thu, 23 Oct 2025 23:53:13 +0530 Subject: [PATCH 1/2] Use exc_info for task instance heartbeat failure exception logging --- task-sdk/src/airflow/sdk/execution_time/supervisor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task-sdk/src/airflow/sdk/execution_time/supervisor.py b/task-sdk/src/airflow/sdk/execution_time/supervisor.py index 368870b0a15f2..9675887cb8a3e 100644 --- a/task-sdk/src/airflow/sdk/execution_time/supervisor.py +++ b/task-sdk/src/airflow/sdk/execution_time/supervisor.py @@ -1129,7 +1129,7 @@ def _send_heartbeat_if_needed(self): except Exception as e: self._handle_heartbeat_failures(e) - def _handle_heartbeat_failures(self, exc: Exception | None): + def _handle_heartbeat_failures(self, exc: Exception): """Increment the failed heartbeats counter and kill the process if too many failures.""" self.failed_heartbeats += 1 log.warning( @@ -1137,7 +1137,7 @@ def _handle_heartbeat_failures(self, exc: Exception | None): failed_heartbeats=self.failed_heartbeats, ti_id=self.id, max_retries=MAX_FAILED_HEARTBEATS, - exception=exc, + exc_info=exc, ) # If we've failed to heartbeat too many times, kill the process if self.failed_heartbeats >= MAX_FAILED_HEARTBEATS: From fa5348b80d3d8234046fdb510be6fcae6d363609 Mon Sep 17 00:00:00 2001 From: Amogh Desai Date: Fri, 24 Oct 2025 01:11:33 +0530 Subject: [PATCH 2/2] fixing tests --- task-sdk/tests/task_sdk/execution_time/test_supervisor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task-sdk/tests/task_sdk/execution_time/test_supervisor.py b/task-sdk/tests/task_sdk/execution_time/test_supervisor.py index 891b0712a2143..7cc057ccdd454 100644 --- a/task-sdk/tests/task_sdk/execution_time/test_supervisor.py +++ b/task-sdk/tests/task_sdk/execution_time/test_supervisor.py @@ -858,7 +858,7 @@ def test_heartbeat_failures_handling(self, monkeypatch, mocker, captured_logs, t "level": "warning", "logger": "supervisor", "timestamp": mocker.ANY, - "exception": mocker.ANY, + "exc_info": mocker.ANY, "loc": mocker.ANY, }