uranusjr commented on code in PR #26040:
URL: https://github.com/apache/airflow/pull/26040#discussion_r959943517
##########
tests/models/test_taskinstance.py:
##########
@@ -2290,6 +2290,26 @@ def test_handle_failure_no_task(self, Stats_incr,
dag_maker):
Stats_incr.assert_any_call('ti_failures')
Stats_incr.assert_any_call('operator_failures_EmptyOperator')
+ def test_handle_failure_task_undefined(self, dag_maker):
+ """
+ When the loaded taskinstance does not use refresh_from_task, the task
may be undefined.
+ For example:
+ the DAG file has been deleted before executing
_execute_task_callbacks
+ """
+ session = settings.Session()
+ with dag_maker():
+ task = EmptyOperator(task_id="mytask", retries=1)
+ dr = dag_maker.create_dagrun()
+
+ ti: Optional[TI] = (
+ session.query(TI)
+ .filter_by(dag_id=task.dag_id, run_id=dr.run_id,
task_id=task.task_id)
+ .one_or_none()
+ )
Review Comment:
```suggestion
ti: TI = (
session.query(TI)
.filter_by(dag_id=task.dag_id, run_id=dr.run_id,
task_id=task.task_id)
.one()
)
```
This test should fail if there’s not an active ti anyway
##########
tests/models/test_taskinstance.py:
##########
@@ -2290,6 +2290,26 @@ def test_handle_failure_no_task(self, Stats_incr,
dag_maker):
Stats_incr.assert_any_call('ti_failures')
Stats_incr.assert_any_call('operator_failures_EmptyOperator')
+ def test_handle_failure_task_undefined(self, dag_maker):
+ """
+ When the loaded taskinstance does not use refresh_from_task, the task
may be undefined.
+ For example:
+ the DAG file has been deleted before executing
_execute_task_callbacks
+ """
+ session = settings.Session()
Review Comment:
There is a `session` fixture for this; don’t create a new one.
--
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]