This is an automated email from the ASF dual-hosted git repository. utkarsharma pushed a commit to branch sync_2-10-test-rc2 in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 23370b5699c0fef5d21dc6483485cd46966b82a1 Author: Pierre Jeambrun <[email protected]> AuthorDate: Wed Oct 30 20:20:17 2024 +0800 Ensure total_entries in /api/v1/dags (#43377) (#43429) * Ensure total_entries in /api/v1/dags * Test total_entries for /api/v1/dags?fields=... (cherry picked from commit 19ddb02812c49dcc50355fa981efa02ed907e735) Co-authored-by: xitep <[email protected]> (cherry picked from commit 6a236922eff46221b770c567344db4a9c512bc7d) --- 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 1895bfeaec..a9f70a96c7 100644 --- a/airflow/api_connexion/endpoints/dag_endpoint.py +++ b/airflow/api_connexion/endpoints/dag_endpoint.py @@ -130,7 +130,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 91354aa177..0ee61236e0 100644 --- a/tests/api_connexion/endpoints/test_dag_endpoint.py +++ b/tests/api_connexion/endpoints/test_dag_endpoint.py @@ -1288,6 +1288,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()
