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

eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 54e7e0824d Fix the dags count filter in webserver home page (#34944)
54e7e0824d is described below

commit 54e7e0824d271900fde35ed066bf6f159a7c6056
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
---
 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 5126b1ff6a..799fea591a 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -830,7 +830,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 4c0ea017e6..95ef19da09 100644
--- a/tests/www/views/test_views_home.py
+++ b/tests/www/views/test_views_home.py
@@ -69,6 +69,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