Copilot commented on code in PR #64568:
URL: https://github.com/apache/airflow/pull/64568#discussion_r3066480464
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -2805,6 +2805,56 @@ def _handle_request(self, msg, log, req_id):
assert isinstance(response, VariableResult)
assert response.value == "value"
+ def test_inprocess_failure_callback_receives_exception(
+ self,
+ monkeypatch,
+ make_ti_context,
+ ):
+ """Run a failing task via InProcessTestSupervisor and ensure the
+ `on_failure_callback` receives `context['exception']`.
+ """
+ collected: list[BaseException | None] = [None]
+
+ class _Failure(Exception):
+ pass
+
+ def failure_callback(context):
+ collected[0] = context.get("exception")
+
+ class FailingOperator(BaseOperator):
+ def execute(self, context=None):
+ raise _Failure("boom")
+
+ task = FailingOperator(task_id="failing",
on_failure_callback=failure_callback)
+
+ # Assign a minimal DAG to the operator so `task.dag` access succeeds
+ from airflow.sdk import DAG
+
+ task.dag = DAG(dag_id="test_dag")
Review Comment:
Avoid importing `DAG` inside the test function; it can be imported at module
level alongside `BaseOperator` (e.g., `from airflow.sdk import BaseOperator,
DAG, timezone`) to keep imports consistent and avoid runtime imports in test
bodies.
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -2805,6 +2805,56 @@ def _handle_request(self, msg, log, req_id):
assert isinstance(response, VariableResult)
assert response.value == "value"
+ def test_inprocess_failure_callback_receives_exception(
+ self,
+ monkeypatch,
+ make_ti_context,
+ ):
+ """Run a failing task via InProcessTestSupervisor and ensure the
+ `on_failure_callback` receives `context['exception']`.
+ """
+ collected: list[BaseException | None] = [None]
+
+ class _Failure(Exception):
+ pass
+
+ def failure_callback(context):
+ collected[0] = context.get("exception")
+
+ class FailingOperator(BaseOperator):
+ def execute(self, context=None):
+ raise _Failure("boom")
+
+ task = FailingOperator(task_id="failing",
on_failure_callback=failure_callback)
+
+ # Assign a minimal DAG to the operator so `task.dag` access succeeds
+ from airflow.sdk import DAG
+
+ task.dag = DAG(dag_id="test_dag")
+
+ # Create a simple TaskInstance datamodel to pass to the supervisor
+ ti = TaskInstance(
+ id=uuid7(),
+ task_id=task.task_id,
+ dag_id="test_dag",
+ run_id="r",
+ try_number=1,
+ dag_version_id=uuid7(),
+ )
+
+ # Patch the API client used by InProcessTestSupervisor to return a
predictable TI context
+ fake_client = MagicMock()
+ fake_client.task_instances.start.return_value = make_ti_context()
Review Comment:
`fake_client = MagicMock()` is an unspecced mock; consider using a
`spec`/`spec_set` (or `autospec`) for the SDK client (and potentially for
`task_instances`) so interface drift/attribute typos don’t silently pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]