houqp commented on a change in pull request #8545:
URL: https://github.com/apache/airflow/pull/8545#discussion_r428324933



##########
File path: airflow/models/dagrun.py
##########
@@ -491,6 +491,25 @@ def is_backfill(self):
             self.run_id.startswith(f"{DagRunType.BACKFILL_JOB.value}")
         )
 
+    @classmethod
+    @provide_session
+    def get_latest_run(cls, dag_id, session):
+        """Returns the latest DagRun for a given dag_id"""
+        subquery = (
+            session
+            .query(func.max(cls.execution_date).label('execution_date'))
+            .filter(cls.dag_id == dag_id)
+            .subquery()
+        )
+        dagrun = (

Review comment:
       can these two queries be combined into one using order by and limit?




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to