amoghrajesh commented on code in PR #64568:
URL: https://github.com/apache/airflow/pull/64568#discussion_r3256506920
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -3086,6 +3086,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
Review Comment:
```suggestion
```
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -3086,6 +3086,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):
Review Comment:
nit, canonical signature is: `def execute(self, context: Context)`
##########
task-sdk/tests/task_sdk/execution_time/test_supervisor.py:
##########
@@ -3086,6 +3086,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
Review Comment:
nit: these comments explain what the code does
--
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]