You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2020/10/25 21:36:30 UTC

[airflow] branch master updated: Dag Run endpoints returns count total results after filtering (#11832)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new c62a49a  Dag Run endpoints returns count total results after filtering (#11832)
c62a49a is described below

commit c62a49af0793247a614c6f25da59908ab5ab5e30
Author: Ephraim Anierobi <sp...@gmail.com>
AuthorDate: Sun Oct 25 22:35:30 2020 +0100

    Dag Run endpoints returns count total results after filtering (#11832)
---
 airflow/api_connexion/endpoints/dag_run_endpoint.py    | 3 ++-
 tests/api_connexion/endpoints/test_dag_run_endpoint.py | 8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/airflow/api_connexion/endpoints/dag_run_endpoint.py b/airflow/api_connexion/endpoints/dag_run_endpoint.py
index b700c35..5be1964 100644
--- a/airflow/api_connexion/endpoints/dag_run_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_run_endpoint.py
@@ -131,7 +131,6 @@ def _fetch_dag_runs(
     limit,
     offset,
 ):
-    total_entries = query.count()
     query = _apply_date_filters_to_query(
         query,
         end_date_gte,
@@ -141,6 +140,8 @@ def _fetch_dag_runs(
         start_date_gte,
         start_date_lte,
     )
+    # Count items
+    total_entries = query.count()
     # apply offset and limit
     dag_run = query.order_by(DagRun.id).offset(offset).limit(limit).all()
     return dag_run, total_entries
diff --git a/tests/api_connexion/endpoints/test_dag_run_endpoint.py b/tests/api_connexion/endpoints/test_dag_run_endpoint.py
index 0ad0c63..7cd0d62 100644
--- a/tests/api_connexion/endpoints/test_dag_run_endpoint.py
+++ b/tests/api_connexion/endpoints/test_dag_run_endpoint.py
@@ -431,7 +431,7 @@ class TestGetDagRunsPaginationFilters(TestDagRunEndpoint):
 
         response = self.client.get(url, environ_overrides={'REMOTE_USER': "test"})
         assert response.status_code == 200
-        assert response.json["total_entries"] == 10
+        assert response.json["total_entries"] == len(expected_dag_run_ids)
         dag_run_ids = [dag_run["dag_run_id"] for dag_run in response.json["dag_runs"]]
         assert dag_run_ids == expected_dag_run_ids
 
@@ -482,7 +482,7 @@ class TestGetDagRunsEndDateFilters(TestDagRunEndpoint):
         self._create_test_dag_run('success')  # state==success, then end date is today
         response = self.client.get(url, environ_overrides={'REMOTE_USER': "test"})
         assert response.status_code == 200
-        assert response.json["total_entries"] == 2
+        assert response.json["total_entries"] == len(expected_dag_run_ids)
         dag_run_ids = [dag_run["dag_run_id"] for dag_run in response.json["dag_runs"] if dag_run]
         assert dag_run_ids == expected_dag_run_ids
 
@@ -706,7 +706,7 @@ class TestGetDagRunBatchDateFilters(TestDagRunEndpoint):
             "api/v1/dags/~/dagRuns/list", json=payload, environ_overrides={'REMOTE_USER': "test"}
         )
         assert response.status_code == 200
-        assert response.json["total_entries"] == 10
+        assert response.json["total_entries"] == len(expected_dag_run_ids)
         dag_run_ids = [dag_run["dag_run_id"] for dag_run in response.json["dag_runs"]]
         assert dag_run_ids == expected_dag_run_ids
 
@@ -760,7 +760,7 @@ class TestGetDagRunBatchDateFilters(TestDagRunEndpoint):
             "api/v1/dags/~/dagRuns/list", json=payload, environ_overrides={'REMOTE_USER': "test"}
         )
         assert response.status_code == 200
-        assert response.json["total_entries"] == 2
+        assert response.json["total_entries"] == len(expected_dag_run_ids)
         dag_run_ids = [dag_run["dag_run_id"] for dag_run in response.json["dag_runs"] if dag_run]
         assert dag_run_ids == expected_dag_run_ids