You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "YoannAbriel (via GitHub)" <gi...@apache.org> on 2026/03/05 08:09:52 UTC

[PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

YoannAbriel opened a new pull request, #62918:
URL: https://github.com/apache/airflow/pull/62918

   ## Problem
   
   Deadline alerts fire even after a DAG run has failed. A user configured a 180-minute deadline, the DAG failed within 10 minutes, but the deadline alert still triggered 3 hours later.
   
   ## Root Cause
   
   `DagRun.update_state()` only calls `Deadline.prune_deadlines()` in the success path. When a DAG run fails (task failure or deadlock), pending deadlines are never cleaned up, so the scheduler still fires them later.
   
   ## Fix
   
   Moved deadline pruning from the success-only block to the shared terminal state block that runs for both SUCCESS and FAILED states. Added a test for the failure case.
   
   Closes: #60927
   
   <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code
   
   Generated-by: Claude Code following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4429931322

   @YoannAbriel can you address failing static checks?


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "YoannAbriel (via GitHub)" <gi...@apache.org>.
YoannAbriel commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4060287928

   Thanks @ferruzzi — updated to keep the logic inside the existing terminal-state if-block as you suggested: `handle_miss()` on FAILED, `prune` on SUCCESS. Appreciate the thorough review!


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r2955194715


##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1224,6 +1212,31 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+            if dag.deadline:
+                deadline_alerts = [
+                    DeadlineAlertModel.get_by_id(alert_id, session) for alert_id in dag.deadline
+                ]
+
+                has_dagrun_deadlines = any(
+                    deadline_alert.reference_class in SerializedReferenceModels.TYPES.DAGRUN
+                    for deadline_alert in deadline_alerts
+                )
+
+                if has_dagrun_deadlines:
+                    if self._state == DagRunState.SUCCESS:
+                        # Run succeeded before deadline — prune so they don't fire.
+                        Deadline.prune_deadlines(session=session, conditions={DagRun.id: self.id})
+                    elif self._state == DagRunState.FAILED:
+                        # Run failed — immediately fire any pending deadline callbacks.
+                        pending_deadlines = session.scalars(
+                            select(Deadline)
+                            .join(DagRun)
+                            .where(DagRun.id == self.id, Deadline.missed == false())

Review Comment:
   I'm not great with SQL so I may be wrong here, but passing on feedback I got in the past:  We should add a `selectinload` to make this more efficient.  Without it, accessing `deadline.callback` and `deadline.dagrun` inside `handle_miss()` triggers a separate DB query for each deadline in the loop. With `selectinload`, those  are loaded one time up front, saving a bunch of DB lookups.
   
   The `~Deadline.missed` is purely semantics and does the same as yours.
   
   ```suggestion
                           pending_deadlines = session.scalars(
                               select(Deadline)
                               .join(DagRun)
                               .where(DagRun.id == self.id, ~Deadline.missed)
                               .options(selectinload(Deadline.callback), selectinload(Deadline.dagrun))
    ```
   
   
   
   Mayyybe it's time to consider moving that db lookup into handle_miss.... but that doesn't have to happen in this PR



##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1224,6 +1212,31 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+            if dag.deadline:
+                deadline_alerts = [
+                    DeadlineAlertModel.get_by_id(alert_id, session) for alert_id in dag.deadline
+                ]
+
+                has_dagrun_deadlines = any(
+                    deadline_alert.reference_class in SerializedReferenceModels.TYPES.DAGRUN
+                    for deadline_alert in deadline_alerts
+                )
+
+                if has_dagrun_deadlines:
+                    if self._state == DagRunState.SUCCESS:
+                        # Run succeeded before deadline — prune so they don't fire.
+                        Deadline.prune_deadlines(session=session, conditions={DagRun.id: self.id})
+                    elif self._state == DagRunState.FAILED:
+                        # Run failed — immediately fire any pending deadline callbacks.
+                        pending_deadlines = session.scalars(
+                            select(Deadline)
+                            .join(DagRun)
+                            .where(DagRun.id == self.id, Deadline.missed == false())

Review Comment:
   Also, is there any particular reason you stored this in a variable instead of just putting it inline in the for loop?



##########
airflow-core/tests/unit/models/test_dagrun.py:
##########
@@ -1349,6 +1349,34 @@ 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, "prune_deadlines")
+    @mock.patch.object(DeadlineAlertModel, "get_by_id")
+    def test_dagrun_failure_does_not_prune_deadlines(
+        self, mock_get_by_id, mock_prune, session, deadline_test_dag
+    ):
+        """On failure, deadlines should NOT be pruned — handle_miss fires instead."""

Review Comment:
   The name says exactly what the test does, no comment needed
   
   ```suggestion
   
   ```



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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "YoannAbriel (via GitHub)" <gi...@apache.org>.
YoannAbriel commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r3035201926


##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1224,6 +1212,31 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+            if dag.deadline:
+                deadline_alerts = [
+                    DeadlineAlertModel.get_by_id(alert_id, session) for alert_id in dag.deadline
+                ]
+
+                has_dagrun_deadlines = any(
+                    deadline_alert.reference_class in SerializedReferenceModels.TYPES.DAGRUN
+                    for deadline_alert in deadline_alerts
+                )
+
+                if has_dagrun_deadlines:
+                    if self._state == DagRunState.SUCCESS:
+                        # Run succeeded before deadline — prune so they don't fire.
+                        Deadline.prune_deadlines(session=session, conditions={DagRun.id: self.id})
+                    elif self._state == DagRunState.FAILED:
+                        # Run failed — immediately fire any pending deadline callbacks.
+                        pending_deadlines = session.scalars(
+                            select(Deadline)
+                            .join(DagRun)
+                            .where(DagRun.id == self.id, Deadline.missed == false())

Review Comment:
   Done — added selectinload for callback and dagrun, and inlined the query.



##########
airflow-core/tests/unit/models/test_dagrun.py:
##########
@@ -1349,6 +1349,34 @@ 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, "prune_deadlines")
+    @mock.patch.object(DeadlineAlertModel, "get_by_id")
+    def test_dagrun_failure_does_not_prune_deadlines(
+        self, mock_get_by_id, mock_prune, session, deadline_test_dag
+    ):
+        """On failure, deadlines should NOT be pruned — handle_miss fires instead."""

Review Comment:
   Removed.



##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1246,6 +1234,26 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+            if dag.deadline:
+                if any(
+                    DeadlineAlertModel.get_by_id(alert_id, session).reference_class
+                    in SerializedReferenceModels.TYPES.DAGRUN
+                    for alert_id in dag.deadline
+                ):
+                    if self._state == DagRunState.SUCCESS:
+                        # Run succeeded before deadline — prune so they don't fire.
+                        Deadline.prune_deadlines(session=session, conditions={DagRun.id: self.id})
+                    elif self._state == DagRunState.FAILED:
+                        # Run failed — immediately fire any pending deadline callbacks.
+                        for deadline in session.scalars(
+                            select(Deadline)
+                            .join(DagRun)
+                            .where(DagRun.id == self.id, ~Deadline.missed)
+                            .options(selectinload(Deadline.callback), selectinload(Deadline.dagrun))
+                        ):
+                            deadline.handle_miss(session=session)

Review Comment:
   Added `test_dagrun_failure_calls_handle_miss` in 5b72205.



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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4182516629

   Moved milestone to 3.2.1 as PR still not approved  I am just about to start rc2 for 3.2.0 


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r3230130473


##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1267,6 +1255,21 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+
+            if dag.deadline:
+                # The dagrun has reached a terminal state. Prune any pending deadlines
+                # so they don't fire after the run is already finished.
+                deadline_alerts = [
+                    DeadlineAlertModel.get_by_id(alert_id, session) for alert_id in dag.deadline
+                ]
+
+                if any(
+                    deadline_alert.reference_class in SerializedReferenceModels.TYPES.DAGRUN
+                    for deadline_alert in deadline_alerts

Review Comment:
   Honestly, I don't really think this is necessary and I'd just resolve it.  Seems like over-optimizing around an edge case where a dagrun has many deadlines as opposed to just using the exiting helper that serves the same purpose. 



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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "YoannAbriel (via GitHub)" <gi...@apache.org>.
YoannAbriel commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4036962463

   Good catch — will update to call handle_miss() on FAILED and only prune on SUCCESS.


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4034777638

   No, not quite the answer we need here.  When you call `prune_deadlines`, it removes that deadline from the list and you'll never get alerted of the miss.  In your example with the Dag that failed after 10 minutes, the Dag's `end_date` will now be before the `deadline_time`, so the `deadline` will be removed from the table, never to be called.  This is the exact opposite of what should happen.  
   
   The right fix would be: when the DagRun transitions to `FAILED`, short-circuit by immediately calling `handle_miss()` on any pending (`missed=False`) deadlines for that DagRun, rather than waiting for `deadline_time` to elapse.  That way when your Dag fails at 10 minutes, your callback fires immediately, informing the user.
   
   You can keep the change you made, but you'll have to wrap the new location in a state check to only call prune on SUCCESS and also add a block for state==FAILED to call handle_miss as well.


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r3066484763


##########
airflow-core/tests/unit/models/test_dagrun.py:
##########
@@ -1360,6 +1360,36 @@ 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, "prune_deadlines")
+    @mock.patch.object(DeadlineAlertModel, "get_by_id")
+    def test_dagrun_failure_prunes_dagrun_deadlines(
+        self, mock_get_by_id, mock_prune, session, deadline_test_dag
+    ):
+        """Deadlines should be pruned when a DAG run fails, not just on success."""
+        mock_deadline_alert = mock.MagicMock()

Review Comment:
   `mock.MagicMock()` is created without a `spec`/`autospec`, which can hide attribute/typo mistakes in tests. Consider using a spec’d mock (or an autospecced patch) matching the `DeadlineAlert` model so the test fails if it relies on non-existent attributes.
   ```suggestion
           mock_deadline_alert = mock.create_autospec(DeadlineAlertModel, instance=True)
   ```



##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1267,6 +1255,21 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+
+            if dag.deadline:
+                # The dagrun has reached a terminal state. Prune any pending deadlines
+                # so they don't fire after the run is already finished.
+                deadline_alerts = [
+                    DeadlineAlertModel.get_by_id(alert_id, session) for alert_id in dag.deadline
+                ]
+
+                if any(
+                    deadline_alert.reference_class in SerializedReferenceModels.TYPES.DAGRUN
+                    for deadline_alert in deadline_alerts

Review Comment:
   `deadline_alerts = [DeadlineAlertModel.get_by_id(...)]` issues one DB query per deadline ID. Since this code runs on every terminal DagRun (now including failures), consider fetching all referenced DeadlineAlert rows in a single query (`id IN (...)`) and then checking whether any reference_class is DagRun-related, to avoid N queries when multiple deadlines are configured.
   ```suggestion
                   deadline_alert_reference_classes = session.execute(
                       select(DeadlineAlertModel.reference_class).where(
                           DeadlineAlertModel.id.in_(set(dag.deadline))
                       )
                   ).scalars()
   
                   if any(
                       reference_class in SerializedReferenceModels.TYPES.DAGRUN
                       for reference_class in deadline_alert_reference_classes
   ```



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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4764148478

   Current head still deletes failed-run deadlines instead of handling them as missed. `Deadline.prune_deadlines()` is only for successful events; on FAILED DagRuns we need to call `handle_miss()` on pending DagRun deadlines so the callback is queued immediately, and keep pruning limited to SUCCESS. Otherwise a DAG that fails before `deadline_time` loses the deadline row and the miss callback never fires.
   


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4179926719

   Tests are failing.


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on PR #62918:
URL: https://github.com/apache/airflow/pull/62918#issuecomment-4040881583

   The change of location isn't necessarily bad, but I think it's somewhat irrelevant.  We can either do 
   
   ```
   if state == SUCCESS:
       prune
   if state == FAILURE:
       handle
       
   the existing if state in [SUCCESS, FAILURE]:   
     existing code
   ```
   
   or 
   
   ```
   the existing if state in [SUCCESS, FAILURE]:   
       if state == SUCCESS:
           prune
       if state == FAILURE:
           handle
      existing code
   ```
   
   I don't think the location itself matters, but maybe inside the existing "if terminal state" block is slightly easier to find/read.


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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "shivaam (via GitHub)" <gi...@apache.org>.
shivaam commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r2998591250


##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1246,6 +1234,26 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+            if dag.deadline:
+                if any(
+                    DeadlineAlertModel.get_by_id(alert_id, session).reference_class
+                    in SerializedReferenceModels.TYPES.DAGRUN
+                    for alert_id in dag.deadline
+                ):
+                    if self._state == DagRunState.SUCCESS:
+                        # Run succeeded before deadline — prune so they don't fire.
+                        Deadline.prune_deadlines(session=session, conditions={DagRun.id: self.id})
+                    elif self._state == DagRunState.FAILED:
+                        # Run failed — immediately fire any pending deadline callbacks.
+                        for deadline in session.scalars(
+                            select(Deadline)
+                            .join(DagRun)
+                            .where(DagRun.id == self.id, ~Deadline.missed)
+                            .options(selectinload(Deadline.callback), selectinload(Deadline.dagrun))
+                        ):
+                            deadline.handle_miss(session=session)

Review Comment:
   Nice fix! One small suggestion on test coverage:
   
   test_dagrun_failure_does_not_prune_deadlines verifies that prune_deadlines is not called on failure, but doesn't verify that handle_miss() is actually called when recalculate() transitions the run to FAILED which is the main behavioral change in this PR.



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


Re: [PR] fix: prune deadline alerts when DAG run fails, not just on success [airflow]

Posted by "shivaam (via GitHub)" <gi...@apache.org>.
shivaam commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r2998591250


##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1246,6 +1234,26 @@ def recalculate(self) -> _UnfinishedStates:
                 self.data_interval_start,
                 self.data_interval_end,
             )
+
+            if dag.deadline:
+                if any(
+                    DeadlineAlertModel.get_by_id(alert_id, session).reference_class
+                    in SerializedReferenceModels.TYPES.DAGRUN
+                    for alert_id in dag.deadline
+                ):
+                    if self._state == DagRunState.SUCCESS:
+                        # Run succeeded before deadline — prune so they don't fire.
+                        Deadline.prune_deadlines(session=session, conditions={DagRun.id: self.id})
+                    elif self._state == DagRunState.FAILED:
+                        # Run failed — immediately fire any pending deadline callbacks.
+                        for deadline in session.scalars(
+                            select(Deadline)
+                            .join(DagRun)
+                            .where(DagRun.id == self.id, ~Deadline.missed)
+                            .options(selectinload(Deadline.callback), selectinload(Deadline.dagrun))
+                        ):
+                            deadline.handle_miss(session=session)

Review Comment:
   Nice fix! One small suggestion on test coverage:
   
   I think it would be nice to also test that handle_miss is called when a dag is marked as failed before the timeout. 
   
   `test_dagrun_failure_does_not_prune_deadlines` verifies that prune_deadlines is not called on failure, but doesn't verify that handle_miss() is actually called when recalculate() transitions the run to FAILED which is the main behavioral change in this PR.



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