Skip to content

Commit

Permalink
Add total_entries to response
Browse files Browse the repository at this point in the history
  • Loading branch information
omkar-foss committed Nov 21, 2024
1 parent ec4e49b commit 2eb2daf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions airflow/api_fastapi/core_api/datamodels/task_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,4 @@ class TaskInstanceReferenceCollectionResponse(BaseModel):
"""Task Instance Reference collection serializer for responses."""

task_instances: list[TaskInstanceReferenceResponse]
total_entries: int
4 changes: 4 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion airflow/api_fastapi/core_api/routes/public/task_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,5 +568,6 @@ def post_clear_task_instances(
from_attributes=True,
)
for ti in task_instances
]
],
total_entries=len(task_instances),
)
6 changes: 5 additions & 1 deletion airflow/ui/openapi-gen/requests/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ export type TaskInstanceHistoryResponse = {
*/
export type TaskInstanceReferenceCollectionResponse = {
task_instances: Array<TaskInstanceReferenceResponse>;
total_entries: number;
};

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/api_fastapi/core_api/routes/public/test_task_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2eb2daf

Please sign in to comment.