diff --git a/airflow/api_fastapi/core_api/datamodels/task_instances.py b/airflow/api_fastapi/core_api/datamodels/task_instances.py index a778c1bd62e28..1c5c5f3f136fc 100644 --- a/airflow/api_fastapi/core_api/datamodels/task_instances.py +++ b/airflow/api_fastapi/core_api/datamodels/task_instances.py @@ -203,3 +203,4 @@ class TaskInstanceReferenceCollectionResponse(BaseModel): """Task Instance Reference collection serializer for responses.""" task_instances: list[TaskInstanceReferenceResponse] + total_entries: int diff --git a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml index 30b7ce6e4e13a..85cbeaabd477d 100644 --- a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml +++ b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml @@ -7006,9 +7006,13 @@ components: $ref: '#/components/schemas/TaskInstanceReferenceResponse' type: array title: Task Instances + total_entries: + type: integer + title: Total Entries type: object required: - task_instances + - total_entries title: TaskInstanceReferenceCollectionResponse description: Task Instance Reference collection serializer for responses. TaskInstanceReferenceResponse: diff --git a/airflow/api_fastapi/core_api/routes/public/task_instances.py b/airflow/api_fastapi/core_api/routes/public/task_instances.py index 8b1440eedab86..8f3fe7af6381d 100644 --- a/airflow/api_fastapi/core_api/routes/public/task_instances.py +++ b/airflow/api_fastapi/core_api/routes/public/task_instances.py @@ -568,5 +568,6 @@ def post_clear_task_instances( from_attributes=True, ) for ti in task_instances - ] + ], + total_entries=len(task_instances), ) diff --git a/airflow/ui/openapi-gen/requests/schemas.gen.ts b/airflow/ui/openapi-gen/requests/schemas.gen.ts index 714a9899a6225..55f897bef0807 100644 --- a/airflow/ui/openapi-gen/requests/schemas.gen.ts +++ b/airflow/ui/openapi-gen/requests/schemas.gen.ts @@ -3453,9 +3453,13 @@ export const $TaskInstanceReferenceCollectionResponse = { type: "array", title: "Task Instances", }, + total_entries: { + type: "integer", + title: "Total Entries", + }, }, type: "object", - required: ["task_instances"], + required: ["task_instances", "total_entries"], title: "TaskInstanceReferenceCollectionResponse", description: "Task Instance Reference collection serializer for responses.", } as const; diff --git a/airflow/ui/openapi-gen/requests/types.gen.ts b/airflow/ui/openapi-gen/requests/types.gen.ts index ef7c131333fd8..33a302e6cb8fc 100644 --- a/airflow/ui/openapi-gen/requests/types.gen.ts +++ b/airflow/ui/openapi-gen/requests/types.gen.ts @@ -859,6 +859,7 @@ export type TaskInstanceHistoryResponse = { */ export type TaskInstanceReferenceCollectionResponse = { task_instances: Array; + total_entries: number; }; /** diff --git a/tests/api_fastapi/core_api/routes/public/test_task_instances.py b/tests/api_fastapi/core_api/routes/public/test_task_instances.py index 74547fa74ff0c..20d9b3bae21d1 100644 --- a/tests/api_fastapi/core_api/routes/public/test_task_instances.py +++ b/tests/api_fastapi/core_api/routes/public/test_task_instances.py @@ -1836,7 +1836,7 @@ def test_should_respond_200( json=payload, ) assert response.status_code == 200 - assert len(response.json()["task_instances"]) == expected_ti + assert response.json()["total_entries"] == expected_ti @mock.patch("airflow.api_fastapi.core_api.routes.public.task_instances.clear_task_instances") def test_clear_taskinstance_is_called_with_queued_dr_state(self, mock_clearti, test_client, session): @@ -1975,7 +1975,7 @@ def test_should_respond_200_with_reset_dag_run(self, test_client, session): ] for task_instance in expected_response: assert task_instance in response.json()["task_instances"] - assert 6 == len(response.json()["task_instances"]) + assert 6 == response.json()["total_entries"] assert 0 == failed_dag_runs, 0 def test_should_respond_200_with_dag_run_id(self, test_client, session): @@ -2033,7 +2033,7 @@ def test_should_respond_200_with_dag_run_id(self, test_client, session): }, ] assert response.json()["task_instances"] == expected_response - assert 1 == len(response.json()["task_instances"]) + assert 1 == response.json()["total_entries"] def test_should_respond_200_with_include_past(self, test_client, session): dag_id = "example_python_operator" @@ -2121,7 +2121,7 @@ def test_should_respond_200_with_include_past(self, test_client, session): ] for task_instance in expected_response: assert task_instance in response.json()["task_instances"] - assert 6 == len(response.json()["task_instances"]) + assert 6 == response.json()["total_entries"] def test_should_respond_200_with_include_future(self, test_client, session): dag_id = "example_python_operator" @@ -2210,7 +2210,7 @@ def test_should_respond_200_with_include_future(self, test_client, session): ] for task_instance in expected_response: assert task_instance in response.json()["task_instances"] - assert 6 == len(response.json()["task_instances"]) + assert 6 == response.json()["total_entries"] def test_should_respond_404_for_nonexistent_dagrun_id(self, test_client, session): dag_id = "example_python_operator"