Skip to content

Commit c83768a

Browse files
AIP-84 constraint wildcard path params for get batch TI (#44175)
1 parent 5f7f95b commit c83768a

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

airflow/api_fastapi/core_api/openapi/v1-generated.yaml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,12 +3620,31 @@ paths:
36203620
summary: Get Task Instances Batch
36213621
description: Get list of task instances.
36223622
operationId: get_task_instances_batch
3623+
parameters:
3624+
- name: dag_id
3625+
in: path
3626+
required: true
3627+
schema:
3628+
enum:
3629+
- '~'
3630+
const: '~'
3631+
type: string
3632+
title: Dag Id
3633+
- name: dag_run_id
3634+
in: path
3635+
required: true
3636+
schema:
3637+
enum:
3638+
- '~'
3639+
const: '~'
3640+
type: string
3641+
title: Dag Run Id
36233642
requestBody:
3643+
required: true
36243644
content:
36253645
application/json:
36263646
schema:
36273647
$ref: '#/components/schemas/TaskInstancesBatchBody'
3628-
required: true
36293648
responses:
36303649
'200':
36313650
description: Successful Response
@@ -3634,23 +3653,23 @@ paths:
36343653
schema:
36353654
$ref: '#/components/schemas/TaskInstanceCollectionResponse'
36363655
'401':
3637-
description: Unauthorized
36383656
content:
36393657
application/json:
36403658
schema:
36413659
$ref: '#/components/schemas/HTTPExceptionResponse'
3660+
description: Unauthorized
36423661
'403':
3643-
description: Forbidden
36443662
content:
36453663
application/json:
36463664
schema:
36473665
$ref: '#/components/schemas/HTTPExceptionResponse'
3666+
description: Forbidden
36483667
'404':
3649-
description: Not Found
36503668
content:
36513669
application/json:
36523670
schema:
36533671
$ref: '#/components/schemas/HTTPExceptionResponse'
3672+
description: Not Found
36543673
'422':
36553674
description: Validation Error
36563675
content:

airflow/api_fastapi/core_api/routes/public/task_instances.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from __future__ import annotations
1919

20-
from typing import Annotated
20+
from typing import Annotated, Literal
2121

2222
from fastapi import Depends, HTTPException, Request, status
2323
from sqlalchemy.orm import Session, joinedload
@@ -339,6 +339,8 @@ def get_task_instances(
339339
responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
340340
)
341341
def get_task_instances_batch(
342+
dag_id: Literal["~"],
343+
dag_run_id: Literal["~"],
342344
body: TaskInstancesBatchBody,
343345
session: Annotated[Session, Depends(get_session)],
344346
) -> TaskInstanceCollectionResponse:

airflow/ui/openapi-gen/queries/queries.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,8 @@ export const usePoolServicePostPool = <
20772077
* Get Task Instances Batch
20782078
* Get list of task instances.
20792079
* @param data The data for the request.
2080+
* @param data.dagId
2081+
* @param data.dagRunId
20802082
* @param data.requestBody
20812083
* @returns TaskInstanceCollectionResponse Successful Response
20822084
* @throws ApiError
@@ -2091,6 +2093,8 @@ export const useTaskInstanceServiceGetTaskInstancesBatch = <
20912093
TData,
20922094
TError,
20932095
{
2096+
dagId: "~";
2097+
dagRunId: "~";
20942098
requestBody: TaskInstancesBatchBody;
20952099
},
20962100
TContext
@@ -2102,12 +2106,16 @@ export const useTaskInstanceServiceGetTaskInstancesBatch = <
21022106
TData,
21032107
TError,
21042108
{
2109+
dagId: "~";
2110+
dagRunId: "~";
21052111
requestBody: TaskInstancesBatchBody;
21062112
},
21072113
TContext
21082114
>({
2109-
mutationFn: ({ requestBody }) =>
2115+
mutationFn: ({ dagId, dagRunId, requestBody }) =>
21102116
TaskInstanceService.getTaskInstancesBatch({
2117+
dagId,
2118+
dagRunId,
21112119
requestBody,
21122120
}) as unknown as Promise<TData>,
21132121
...options,

airflow/ui/openapi-gen/requests/services.gen.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,8 @@ export class TaskInstanceService {
19311931
* Get Task Instances Batch
19321932
* Get list of task instances.
19331933
* @param data The data for the request.
1934+
* @param data.dagId
1935+
* @param data.dagRunId
19341936
* @param data.requestBody
19351937
* @returns TaskInstanceCollectionResponse Successful Response
19361938
* @throws ApiError
@@ -1941,6 +1943,10 @@ export class TaskInstanceService {
19411943
return __request(OpenAPI, {
19421944
method: "POST",
19431945
url: "/public/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/list",
1946+
path: {
1947+
dag_id: data.dagId,
1948+
dag_run_id: data.dagRunId,
1949+
},
19441950
body: data.requestBody,
19451951
mediaType: "application/json",
19461952
errors: {

airflow/ui/openapi-gen/requests/types.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,8 @@ export type GetTaskInstancesData = {
15051505
export type GetTaskInstancesResponse = TaskInstanceCollectionResponse;
15061506

15071507
export type GetTaskInstancesBatchData = {
1508+
dagId: "~";
1509+
dagRunId: "~";
15081510
requestBody: TaskInstancesBatchBody;
15091511
};
15101512

tests/api_fastapi/core_api/routes/public/test_task_instances.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,19 @@ def test_should_raise_400_for_no_json(self, test_client):
13411341
},
13421342
]
13431343

1344+
def test_should_respond_422_for_non_wildcard_path_parameters(self, test_client):
1345+
response = test_client.post(
1346+
"/public/dags/non_wildcard/dagRuns/~/taskInstances/list",
1347+
)
1348+
assert response.status_code == 422
1349+
assert "Input should be '~'" in str(response.json()["detail"])
1350+
1351+
response = test_client.post(
1352+
"/public/dags/~/dagRuns/non_wildcard/taskInstances/list",
1353+
)
1354+
assert response.status_code == 422
1355+
assert "Input should be '~'" in str(response.json()["detail"])
1356+
13441357
@pytest.mark.parametrize(
13451358
"payload, expected",
13461359
[

0 commit comments

Comments
 (0)