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

pierrejeambrun 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 19ddb02812c Ensure total_entries in /api/v1/dags (#43377)
19ddb02812c is described below

commit 19ddb02812c49dcc50355fa981efa02ed907e735
Author: xitep <[email protected]>
AuthorDate: Mon Oct 28 09:29:25 2024 +0100

    Ensure total_entries in /api/v1/dags (#43377)
    
    * Ensure total_entries in /api/v1/dags
    
    * Test total_entries for /api/v1/dags?fields=...
---
 airflow/api_connexion/endpoints/dag_endpoint.py    |  2 +-
 tests/api_connexion/endpoints/test_dag_endpoint.py | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/airflow/api_connexion/endpoints/dag_endpoint.py 
b/airflow/api_connexion/endpoints/dag_endpoint.py
index 0352297bfff..352bf9cfd4c 100644
--- a/airflow/api_connexion/endpoints/dag_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_endpoint.py
@@ -134,7 +134,7 @@ def get_dags(
 
     try:
         dags_collection_schema = (
-            DAGCollectionSchema(only=[f"dags.{field}" for field in fields])
+            DAGCollectionSchema(only=[f"dags.{field}" for field in fields] + 
["total_entries"])
             if fields
             else DAGCollectionSchema()
         )
diff --git a/tests/api_connexion/endpoints/test_dag_endpoint.py 
b/tests/api_connexion/endpoints/test_dag_endpoint.py
index 41b77d6191a..83785fdbc1d 100644
--- a/tests/api_connexion/endpoints/test_dag_endpoint.py
+++ b/tests/api_connexion/endpoints/test_dag_endpoint.py
@@ -1145,6 +1145,26 @@ class TestGetDags(TestDagEndpoint):
             for field in fields:
                 assert field in dag
 
+    def test_should_return_specified_fields_and_total_entries(self):
+        total = 4
+        self._create_dag_models(total)
+        self._create_deactivated_dag()
+
+        limit = 2
+        fields = ["dag_id"]
+        response = self.client.get(
+            f"api/v1/dags?limit={limit}&fields={','.join(fields)}", 
environ_overrides={"REMOTE_USER": "test"}
+        )
+        assert response.status_code == 200
+
+        res_json = response.json
+        assert res_json["total_entries"] == total
+        assert len(res_json["dags"]) == limit
+        for dag in res_json["dags"]:
+            assert len(dag.keys()) == len(fields)
+            for field in fields:
+                assert field in dag
+
     def test_should_respond_400_with_not_exists_fields(self):
         self._create_dag_models(1)
         self._create_deactivated_dag()

Reply via email to