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


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dashboard.py:
##########
@@ -127,7 +127,20 @@ def dag_stats(
         .subquery()
     )
 
-    latest_runs = (
+    # Active DAGs need another query from DagModel, as a DAG may not have any 
runs but still be active
+    dags_cte = (
+        select(DagModel.dag_id, DagModel.is_paused)
+        .where(DagModel.is_stale == false())
+        .where(DagModel.dag_id.in_(permitted_dag_ids))
+        .cte()
+    )
+    active_count_query = select(
+        func.coalesce(func.sum(case((dags_cte.c.is_paused == false(), 1))), 
0).label("active")
+    ).select_from(dags_cte)
+    active_count = session.execute(active_count_query).first().active

Review Comment:
   You're right thanks, I followed the same construct as other metrics but it's 
obviously simple to do it this way. Updated.



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dashboard.py:
##########
@@ -127,7 +127,20 @@ def dag_stats(
         .subquery()
     )
 
-    latest_runs = (
+    # Active DAGs need another query from DagModel, as a DAG may not have any 
runs but still be active
+    dags_cte = (
+        select(DagModel.dag_id, DagModel.is_paused)
+        .where(DagModel.is_stale == false())
+        .where(DagModel.dag_id.in_(permitted_dag_ids))
+        .cte()
+    )
+    active_count_query = select(
+        func.coalesce(func.sum(case((dags_cte.c.is_paused == false(), 1))), 
0).label("active")
+    ).select_from(dags_cte)
+    active_count = session.execute(active_count_query).first().active

Review Comment:
   You're right thanks, I followed the same construct as other metrics but it's 
obviously simpler to do it this way. Updated.



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