From f9c7b79220cc26cbd59ed17f24543838468911da Mon Sep 17 00:00:00 2001 From: Ephraim Anierobi Date: Wed, 6 Sep 2023 18:58:55 +0100 Subject: [PATCH] Fix query bug in next_run_datasets_summary endpoint The query to get the dataset_triggered_dag_ids in the next_run_datasets_summary endpoint errors with `str` object has no attribute dag_id. This issue is from a recent refactor on sqlalchemy queries and the view has no unit test to detect it. I added a fix with a unit test --- airflow/www/views.py | 4 ++-- tests/www/views/test_views_dataset.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index 50560fac636b4..8be5bb1ed101b 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -1087,8 +1087,8 @@ def next_run_datasets_summary(self, session: Session = NEW_SESSION): filter_dag_ids = allowed_dag_ids dataset_triggered_dag_ids = [ - dag.dag_id - for dag in ( + dag_id + for dag_id in ( session.scalars( select(DagModel.dag_id) .where(DagModel.dag_id.in_(filter_dag_ids)) diff --git a/tests/www/views/test_views_dataset.py b/tests/www/views/test_views_dataset.py index 2a48cb75c4983..f2968faea19d7 100644 --- a/tests/www/views/test_views_dataset.py +++ b/tests/www/views/test_views_dataset.py @@ -440,3 +440,14 @@ def test_should_return_max_if_req_above(self, admin_client, session): assert response.status_code == 200 assert len(response.json["datasets"]) == 50 + + +class TestGetDatasetNextRunSummary(TestDatasetEndpoint): + def test_next_run_dataset_summary(self, dag_maker, admin_client): + with dag_maker(dag_id="upstream", schedule=[Dataset(uri="s3://bucket/key/1")], serialized=True): + EmptyOperator(task_id="task1") + + response = admin_client.post("/next_run_datasets_summary", data={"dag_ids": ["upstream"]}) + + assert response.status_code == 200 + assert response.json == {"upstream": {"ready": 0, "total": 1, "uri": "s3://bucket/key/1"}}