From 07cb814fc42377b87c33e5215f5ed8c93d30a2db Mon Sep 17 00:00:00 2001 From: Hussein Awala Date: Sat, 14 Oct 2023 19:09:33 +0200 Subject: [PATCH 1/2] Fix the dags count filter in webserver home page --- airflow/www/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index 8495f15d07a90..cb5958444fbb5 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -830,7 +830,9 @@ def index(self): 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() ) From 4f1a4cd7438b356d5b828fd74d3a24f73b6a68b6 Mon Sep 17 00:00:00 2001 From: Hussein Awala Date: Sat, 14 Oct 2023 23:54:01 +0200 Subject: [PATCH 2/2] Add a test to avoid breaking the count in the future --- tests/www/views/test_views_home.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/www/views/test_views_home.py b/tests/www/views/test_views_home.py index 4c0ea017e6478..95ef19da09a19 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)