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


##########
airflow-core/src/airflow/models/deadline.py:
##########
@@ -98,6 +98,61 @@ def _determine_resource() -> tuple[str, str]:
             f"{self.deadline_time} or run: {self.callback}({callback_kwargs})"
         )
 
+    @classmethod
+    @provide_session
+    def remove_deadlines(cls, *, session: Session, conditions: dict[Column, 
Any]) -> int:
+        """
+        Remove deadlines from the table which match the provided conditions 
and return the number removed.
+
+        NOTE: This should only be used to remove deadlines which are 
associated with
+            successful dagruns. If the deadline was missed, move it to the 
`missed_deadlines`
+            table after executing the callback.
+        TODO:  Create the missed_deadlines table (Ramit)
+
+        :param conditions: Dictionary of conditions to evaluate against.
+        :param session: Session to use.
+        """
+        from airflow.models import DagRun  # Avoids circular import
+
+        # Assemble the filter conditions.
+        filter_conditions = [column == value for column, value in 
conditions.items()]
+        if not filter_conditions:
+            return 0
+
+        try:
+            # Get deadlines which match the provided conditions and their 
associated DagRuns.
+            deadline_dagrun_pairs = (
+                session.query(Deadline, 
DagRun).join(DagRun).filter(and_(*filter_conditions)).all()
+            )
+        except SQLAlchemyError as e:

Review Comment:
   I put that in there for some edge case and can't figure out what ti was.   
In the end, an invalid column will raise an AttributeError on the model before 
it ever reaches a SQLAlchemy error, so I'm just going to scope that down to 
AttributeError, log it, rollback the change, and re-raise.  Running static 
checks now and I'll get that fix up in the morning.



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