Skip to content

Commit 6a23692

Browse files
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 19ddb02) Co-authored-by: xitep <[email protected]>
1 parent bd19bf8 commit 6a23692

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

airflow/api_connexion/endpoints/dag_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_dags(
130130

131131
try:
132132
dags_collection_schema = (
133-
DAGCollectionSchema(only=[f"dags.{field}" for field in fields])
133+
DAGCollectionSchema(only=[f"dags.{field}" for field in fields] + ["total_entries"])
134134
if fields
135135
else DAGCollectionSchema()
136136
)

tests/api_connexion/endpoints/test_dag_endpoint.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,26 @@ def test_should_return_specified_fields(self):
12881288
for field in fields:
12891289
assert field in dag
12901290

1291+
def test_should_return_specified_fields_and_total_entries(self):
1292+
total = 4
1293+
self._create_dag_models(total)
1294+
self._create_deactivated_dag()
1295+
1296+
limit = 2
1297+
fields = ["dag_id"]
1298+
response = self.client.get(
1299+
f"api/v1/dags?limit={limit}&fields={','.join(fields)}", environ_overrides={"REMOTE_USER": "test"}
1300+
)
1301+
assert response.status_code == 200
1302+
1303+
res_json = response.json
1304+
assert res_json["total_entries"] == total
1305+
assert len(res_json["dags"]) == limit
1306+
for dag in res_json["dags"]:
1307+
assert len(dag.keys()) == len(fields)
1308+
for field in fields:
1309+
assert field in dag
1310+
12911311
def test_should_respond_400_with_not_exists_fields(self):
12921312
self._create_dag_models(1)
12931313
self._create_deactivated_dag()

0 commit comments

Comments
 (0)