pierrejeambrun commented on code in PR #46626:
URL: https://github.com/apache/airflow/pull/46626#discussion_r1954455469


##########
airflow/models/dagrun.py:
##########
@@ -300,6 +297,21 @@ def validate_run_id(self, key: str, run_id: str) -> str | 
None:
             f"The run_id provided '{run_id}' does not match regex pattern 
'{regex}' or '{RUN_ID_REGEX}'"
         )
 
+    @provide_session
+    def dag_versions(self, session: Session = NEW_SESSION) -> list[DagVersion]:
+        """
+        Return the DAG versions associated with the TIs of this DagRun.
+
+        :param session: database session
+        """
+        tis = session.scalars(
+            select(TI.dag_version_id).where(TI.run_id == self.run_id, 
TI.dag_id == self.dag_id).distinct()
+        ).all()
+        tih = session.scalars(
+            select(TIH.dag_version_id).where(TIH.run_id == self.run_id, 
TIH.dag_id == self.dag_id).distinct()
+        ).all()
+        return list(tis + tih)

Review Comment:
   cache_property will not solve it. Each DagRun will run the query for the 
property once.
   
   Yes we can merge like this to not block it but we need a follow up PR 
because this will not work for the rest api. (200 queries emitted per dag run 
page is a lot)



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