ferruzzi commented on code in PR #68961:
URL: https://github.com/apache/airflow/pull/68961#discussion_r3531627914


##########
airflow-core/src/airflow/migrations/versions/0124_3_3_0_add_fire_on_failure_to_deadline_alert.py:
##########
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Add fire_on_failure to deadline_alert.
+
+Revision ID: b4f8c2a1d9e0
+Revises: d2f4e1b3c5a7
+Create Date: 2026-07-01 12:00:00.000000
+"""
+
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+revision = "b4f8c2a1d9e0"
+down_revision = "d2f4e1b3c5a7"
+branch_labels = None
+depends_on = None
+airflow_version = "3.3.0"

Review Comment:
   3.3.0 shipped this morning, so that ship has sailed; bump this to 3.4.0 I 
guess?



##########
airflow-core/tests/unit/models/test_dagrun.py:
##########
@@ -1505,6 +1532,225 @@ def 
test_dagrun_success_handles_empty_deadline_list(self, mock_prune, dag_maker,
         mock_prune.assert_not_called()
         assert dag_run.state == DagRunState.SUCCESS
 
+    @mock.patch.object(Deadline, "handle_miss")
+    @mock.patch.object(Deadline, "prune_deadlines")
+    def test_dagrun_failure_handles_pending_deadline(
+        self, mock_prune, mock_handle_miss, session, deadline_test_dag
+    ):
+        scheduler_dag = deadline_test_dag()
+
+        dag_run = self.create_dag_run(
+            dag=scheduler_dag,
+            task_states={"task_1": TaskInstanceState.SUCCESS, "task_2": 
TaskInstanceState.FAILED},
+            session=session,
+        )
+        deadline_alert = self.create_deadline_alert_model(
+            scheduler_dag, session=session, fire_on_failure=True
+        )
+        scheduler_dag.deadline = [str(deadline_alert.id)]
+        dag_run.dag = scheduler_dag
+        session.add(
+            Deadline(
+                deadline_time=timezone.utcnow() + datetime.timedelta(hours=3),
+                callback=AsyncCallback(empty_callback_for_deadline),
+                dagrun_id=dag_run.id,
+                dag_id=dag_run.dag_id,
+                deadline_alert_id=deadline_alert.id,
+            )
+        )
+        session.flush()
+
+        dag_run.update_state(session=session)
+
+        mock_handle_miss.assert_called_once()
+        mock_prune.assert_not_called()
+        assert dag_run.state == DagRunState.FAILED
+
+    @mock.patch.object(Deadline, "handle_miss")
+    def test_dagrun_deadlock_handles_pending_deadline(self, mock_handle_miss, 
dag_maker, session):
+        with dag_maker(
+            dag_id="test_dagrun_deadlock_handles_pending_deadline",
+            schedule=datetime.timedelta(days=1),
+            session=session,
+        ):
+            up = EmptyOperator(task_id="upstream")
+            middle = EmptyOperator(task_id="wrong")
+            down = EmptyOperator(task_id="downstream")
+
+            middle.trigger_rule = TriggerRule.ONE_FAILED
+            middle.set_upstream(up)
+            middle.set_downstream(down)
+
+        dag_run = dag_maker.create_dagrun()
+        scheduler_dag = dag_run.get_dag()
+        deadline_alert = self.create_deadline_alert_model(
+            scheduler_dag, session=session, fire_on_failure=True
+        )
+        scheduler_dag.deadline = [str(deadline_alert.id)]
+        dag_run.dag = scheduler_dag
+        session.add(
+            Deadline(
+                deadline_time=timezone.utcnow() + datetime.timedelta(hours=3),
+                callback=AsyncCallback(empty_callback_for_deadline),
+                dagrun_id=dag_run.id,
+                dag_id=dag_run.dag_id,
+                deadline_alert_id=deadline_alert.id,
+            )
+        )
+
+        ti_up: TI = dag_run.get_task_instance(task_id=up.task_id, 
session=session)
+        ti_middle: TI = dag_run.get_task_instance(task_id=middle.task_id, 
session=session)
+        ti_up.set_state(state=TaskInstanceState.SUCCESS, session=session)
+        ti_middle.set_state(state=None, session=session)
+        ti_middle.task.trigger_rule = "invalid"
+        session.flush()
+
+        dag_run.update_state(session=session)
+
+        mock_handle_miss.assert_called_once()
+        assert dag_run.state == DagRunState.FAILED
+

Review Comment:
   Do we want a unit test for the case where the DeadlineAlert has already been 
missed and assert that is isn't re-fired on failure?
   
   If the deadline alert is for 10 seconds, fire_on_failure=True, and the dag 
fails at 1 minute, do we expect that to fire again?
   
   The query uses `~Deadline.missed` so it shouldn't fire again, which I think 
is correct;  we just don't have a test to verify it or prevent regression.



-- 
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]

Reply via email to