You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/08/02 08:15:03 UTC
[GitHub] [airflow] ephraimbuddy commented on a change in pull request #17347: Handle and log exceptions raised during task callback
ephraimbuddy commented on a change in pull request #17347:
URL: https://github.com/apache/airflow/pull/17347#discussion_r680764255
##########
File path: tests/models/test_taskinstance.py
##########
@@ -1743,6 +1743,32 @@ def on_execute_callable(context):
ti.refresh_from_db()
assert ti.state == State.SUCCESS
+ def test_success_callback_handles_and_logs_exception(self):
+ called = completed = False
+
+ def on_success_callable(context):
+ nonlocal called, completed
+ called = True
+ raise KeyError
+ completed = True
+
+ dag = DAG(
+ 'test_success_callback_handles_exception',
+ start_date=DEFAULT_DATE,
+ end_date=DEFAULT_DATE + datetime.timedelta(days=10),
+ )
+ task = DummyOperator(
+ task_id='op', email='test@test.test', on_success_callback=on_success_callable, dag=dag
+ )
Review comment:
```suggestion
def test_success_callback_handles_and_logs_exception(self, dag_maker):
called = completed = False
def on_success_callable(context):
nonlocal called, completed
called = True
raise KeyError
completed = True
with dag_maker(
'test_success_callback_handles_exception',
end_date=DEFAULT_DATE + datetime.timedelta(days=10),
) :
task = DummyOperator(
task_id='op', email='test@test.test', on_success_callback=on_success_callable
)
dag_maker.create_dagrun()
```
we recently introduced the `dag_maker` fixture so that we can reduce code duplication and also create dagrun whenever we create a dag.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org