Skip to content

Commit

Permalink
Fix the dags count filter in webserver home page (#34944)
Browse files Browse the repository at this point in the history
* Fix the dags count filter in webserver home page

* Add a test to avoid breaking the count in the future

(cherry picked from commit 54e7e08)
  • Loading branch information
hussein-awala authored and ephraimbuddy committed Oct 30, 2023
1 parent 7ebc494 commit 99e6a43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,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()
)

Expand Down
19 changes: 19 additions & 0 deletions tests/www/views/test_views_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 99e6a43

Please sign in to comment.