This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch v2-7-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 78de303b000a725d7d9716f0aea973224cc4fbaf
Author: Hussein Awala <huss...@awala.fr>
AuthorDate: Sun Oct 15 07:25:34 2023 +0200

    Fix the dags count filter in webserver home page (#34944)
    
    * Fix the dags count filter in webserver home page
    
    * Add a test to avoid breaking the count in the future
    
    (cherry picked from commit 54e7e0824d271900fde35ed066bf6f159a7c6056)
---
 airflow/www/views.py               |  4 +++-
 tests/www/views/test_views_home.py | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/airflow/www/views.py b/airflow/www/views.py
index b55af8ff40..2c7d5adffc 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -840,7 +840,9 @@ class Airflow(AirflowBaseView):
 
             is_paused_count = dict(
                 session.execute(
-                    select(DagModel.is_paused, 
func.count(DagModel.dag_id)).group_by(DagModel.is_paused)
+                    all_dags.with_only_columns([DagModel.is_paused, 
func.count()]).group_by(
+                        DagModel.is_paused
+                    )
                 ).all()
             )
 
diff --git a/tests/www/views/test_views_home.py 
b/tests/www/views/test_views_home.py
index cafff3a54c..cedeb25385 100644
--- a/tests/www/views/test_views_home.py
+++ b/tests/www/views/test_views_home.py
@@ -70,6 +70,25 @@ def test_home(capture_templates, admin_client):
     assert templates[0].local_context["state_color"] == state_color_mapping
 
 
+@mock.patch("airflow.www.views.AirflowBaseView.render_template")
+def test_home_dags_count(render_template_mock, admin_client, working_dags, 
session):
+    from sqlalchemy import update
+
+    from airflow.models.dag import DagModel
+
+    def call_kwargs():
+        return render_template_mock.call_args.kwargs
+
+    admin_client.get("home", follow_redirects=True)
+    assert call_kwargs()["status_count_all"] == 4
+
+    update_stmt = update(DagModel).where(DagModel.dag_id == 
"filter_test_1").values(is_active=False)
+    session.execute(update_stmt)
+
+    admin_client.get("home", follow_redirects=True)
+    assert call_kwargs()["status_count_all"] == 3
+
+
 def test_home_status_filter_cookie(admin_client):
     with admin_client:
         admin_client.get("home", follow_redirects=True)

Reply via email to