Skip to content

Commit adb4d2a

Browse files
AIP-84 Get Mapped Task Instance (apache#43548)
1 parent 0531e78 commit adb4d2a

File tree

10 files changed

+382
-1
lines changed

10 files changed

+382
-1
lines changed

airflow/api_connexion/endpoints/task_instance_endpoint.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def get_task_instance(
104104
return task_instance_schema.dump(task_instance)
105105

106106

107+
@mark_fastapi_migration_done
107108
@security.requires_access_dag("GET", DagAccessEntity.TASK_INSTANCE)
108109
@provide_session
109110
def get_mapped_task_instance(

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

+63
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,69 @@ paths:
14911491
application/json:
14921492
schema:
14931493
$ref: '#/components/schemas/HTTPValidationError'
1494+
/public/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/{map_index}:
1495+
get:
1496+
tags:
1497+
- Task Instance
1498+
summary: Get Mapped Task Instance
1499+
description: Get task instance.
1500+
operationId: get_mapped_task_instance
1501+
parameters:
1502+
- name: dag_id
1503+
in: path
1504+
required: true
1505+
schema:
1506+
type: string
1507+
title: Dag Id
1508+
- name: dag_run_id
1509+
in: path
1510+
required: true
1511+
schema:
1512+
type: string
1513+
title: Dag Run Id
1514+
- name: task_id
1515+
in: path
1516+
required: true
1517+
schema:
1518+
type: string
1519+
title: Task Id
1520+
- name: map_index
1521+
in: path
1522+
required: true
1523+
schema:
1524+
type: integer
1525+
title: Map Index
1526+
responses:
1527+
'200':
1528+
description: Successful Response
1529+
content:
1530+
application/json:
1531+
schema:
1532+
$ref: '#/components/schemas/TaskInstanceResponse'
1533+
'401':
1534+
content:
1535+
application/json:
1536+
schema:
1537+
$ref: '#/components/schemas/HTTPExceptionResponse'
1538+
description: Unauthorized
1539+
'403':
1540+
content:
1541+
application/json:
1542+
schema:
1543+
$ref: '#/components/schemas/HTTPExceptionResponse'
1544+
description: Forbidden
1545+
'404':
1546+
content:
1547+
application/json:
1548+
schema:
1549+
$ref: '#/components/schemas/HTTPExceptionResponse'
1550+
description: Not Found
1551+
'422':
1552+
description: Validation Error
1553+
content:
1554+
application/json:
1555+
schema:
1556+
$ref: '#/components/schemas/HTTPValidationError'
14941557
/public/variables/{variable_key}:
14951558
delete:
14961559
tags:

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

+28-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ async def get_task_instance(
4444
.join(TI.dag_run)
4545
.options(joinedload(TI.rendered_task_instance_fields))
4646
)
47-
4847
task_instance = session.scalar(query)
4948

5049
if task_instance is None:
@@ -56,3 +55,31 @@ async def get_task_instance(
5655
raise HTTPException(404, "Task instance is mapped, add the map_index value to the URL")
5756

5857
return TaskInstanceResponse.model_validate(task_instance, from_attributes=True)
58+
59+
60+
@task_instances_router.get(
61+
"/{task_id}/{map_index}", responses=create_openapi_http_exception_doc([401, 403, 404])
62+
)
63+
async def get_mapped_task_instance(
64+
dag_id: str,
65+
dag_run_id: str,
66+
task_id: str,
67+
map_index: int,
68+
session: Annotated[Session, Depends(get_session)],
69+
) -> TaskInstanceResponse:
70+
"""Get task instance."""
71+
query = (
72+
select(TI)
73+
.where(TI.dag_id == dag_id, TI.run_id == dag_run_id, TI.task_id == task_id, TI.map_index == map_index)
74+
.join(TI.dag_run)
75+
.options(joinedload(TI.rendered_task_instance_fields))
76+
)
77+
task_instance = session.scalar(query)
78+
79+
if task_instance is None:
80+
raise HTTPException(
81+
404,
82+
f"The Mapped Task Instance with dag_id: `{dag_id}`, run_id: `{dag_run_id}`, task_id: `{task_id}`, and map_index: `{map_index}` was not found",
83+
)
84+
85+
return TaskInstanceResponse.model_validate(task_instance, from_attributes=True)

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

+26
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,32 @@ export const UseTaskInstanceServiceGetTaskInstanceKeyFn = (
423423
useTaskInstanceServiceGetTaskInstanceKey,
424424
...(queryKey ?? [{ dagId, dagRunId, taskId }]),
425425
];
426+
export type TaskInstanceServiceGetMappedTaskInstanceDefaultResponse = Awaited<
427+
ReturnType<typeof TaskInstanceService.getMappedTaskInstance>
428+
>;
429+
export type TaskInstanceServiceGetMappedTaskInstanceQueryResult<
430+
TData = TaskInstanceServiceGetMappedTaskInstanceDefaultResponse,
431+
TError = unknown,
432+
> = UseQueryResult<TData, TError>;
433+
export const useTaskInstanceServiceGetMappedTaskInstanceKey =
434+
"TaskInstanceServiceGetMappedTaskInstance";
435+
export const UseTaskInstanceServiceGetMappedTaskInstanceKeyFn = (
436+
{
437+
dagId,
438+
dagRunId,
439+
mapIndex,
440+
taskId,
441+
}: {
442+
dagId: string;
443+
dagRunId: string;
444+
mapIndex: number;
445+
taskId: string;
446+
},
447+
queryKey?: Array<unknown>,
448+
) => [
449+
useTaskInstanceServiceGetMappedTaskInstanceKey,
450+
...(queryKey ?? [{ dagId, dagRunId, mapIndex, taskId }]),
451+
];
426452
export type VariableServiceGetVariableDefaultResponse = Awaited<
427453
ReturnType<typeof VariableService.getVariable>
428454
>;

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

+40
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,46 @@ export const prefetchUseTaskInstanceServiceGetTaskInstance = (
530530
queryFn: () =>
531531
TaskInstanceService.getTaskInstance({ dagId, dagRunId, taskId }),
532532
});
533+
/**
534+
* Get Mapped Task Instance
535+
* Get task instance.
536+
* @param data The data for the request.
537+
* @param data.dagId
538+
* @param data.dagRunId
539+
* @param data.taskId
540+
* @param data.mapIndex
541+
* @returns TaskInstanceResponse Successful Response
542+
* @throws ApiError
543+
*/
544+
export const prefetchUseTaskInstanceServiceGetMappedTaskInstance = (
545+
queryClient: QueryClient,
546+
{
547+
dagId,
548+
dagRunId,
549+
mapIndex,
550+
taskId,
551+
}: {
552+
dagId: string;
553+
dagRunId: string;
554+
mapIndex: number;
555+
taskId: string;
556+
},
557+
) =>
558+
queryClient.prefetchQuery({
559+
queryKey: Common.UseTaskInstanceServiceGetMappedTaskInstanceKeyFn({
560+
dagId,
561+
dagRunId,
562+
mapIndex,
563+
taskId,
564+
}),
565+
queryFn: () =>
566+
TaskInstanceService.getMappedTaskInstance({
567+
dagId,
568+
dagRunId,
569+
mapIndex,
570+
taskId,
571+
}),
572+
});
533573
/**
534574
* Get Variable
535575
* Get a variable entry.

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

+44
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,50 @@ export const useTaskInstanceServiceGetTaskInstance = <
680680
TaskInstanceService.getTaskInstance({ dagId, dagRunId, taskId }) as TData,
681681
...options,
682682
});
683+
/**
684+
* Get Mapped Task Instance
685+
* Get task instance.
686+
* @param data The data for the request.
687+
* @param data.dagId
688+
* @param data.dagRunId
689+
* @param data.taskId
690+
* @param data.mapIndex
691+
* @returns TaskInstanceResponse Successful Response
692+
* @throws ApiError
693+
*/
694+
export const useTaskInstanceServiceGetMappedTaskInstance = <
695+
TData = Common.TaskInstanceServiceGetMappedTaskInstanceDefaultResponse,
696+
TError = unknown,
697+
TQueryKey extends Array<unknown> = unknown[],
698+
>(
699+
{
700+
dagId,
701+
dagRunId,
702+
mapIndex,
703+
taskId,
704+
}: {
705+
dagId: string;
706+
dagRunId: string;
707+
mapIndex: number;
708+
taskId: string;
709+
},
710+
queryKey?: TQueryKey,
711+
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
712+
) =>
713+
useQuery<TData, TError>({
714+
queryKey: Common.UseTaskInstanceServiceGetMappedTaskInstanceKeyFn(
715+
{ dagId, dagRunId, mapIndex, taskId },
716+
queryKey,
717+
),
718+
queryFn: () =>
719+
TaskInstanceService.getMappedTaskInstance({
720+
dagId,
721+
dagRunId,
722+
mapIndex,
723+
taskId,
724+
}) as TData,
725+
...options,
726+
});
683727
/**
684728
* Get Variable
685729
* Get a variable entry.

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

+44
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,50 @@ export const useTaskInstanceServiceGetTaskInstanceSuspense = <
668668
TaskInstanceService.getTaskInstance({ dagId, dagRunId, taskId }) as TData,
669669
...options,
670670
});
671+
/**
672+
* Get Mapped Task Instance
673+
* Get task instance.
674+
* @param data The data for the request.
675+
* @param data.dagId
676+
* @param data.dagRunId
677+
* @param data.taskId
678+
* @param data.mapIndex
679+
* @returns TaskInstanceResponse Successful Response
680+
* @throws ApiError
681+
*/
682+
export const useTaskInstanceServiceGetMappedTaskInstanceSuspense = <
683+
TData = Common.TaskInstanceServiceGetMappedTaskInstanceDefaultResponse,
684+
TError = unknown,
685+
TQueryKey extends Array<unknown> = unknown[],
686+
>(
687+
{
688+
dagId,
689+
dagRunId,
690+
mapIndex,
691+
taskId,
692+
}: {
693+
dagId: string;
694+
dagRunId: string;
695+
mapIndex: number;
696+
taskId: string;
697+
},
698+
queryKey?: TQueryKey,
699+
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
700+
) =>
701+
useSuspenseQuery<TData, TError>({
702+
queryKey: Common.UseTaskInstanceServiceGetMappedTaskInstanceKeyFn(
703+
{ dagId, dagRunId, mapIndex, taskId },
704+
queryKey,
705+
),
706+
queryFn: () =>
707+
TaskInstanceService.getMappedTaskInstance({
708+
dagId,
709+
dagRunId,
710+
mapIndex,
711+
taskId,
712+
}) as TData,
713+
...options,
714+
});
671715
/**
672716
* Get Variable
673717
* Get a variable entry.

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

+34
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import type {
5656
GetProvidersResponse,
5757
GetTaskInstanceData,
5858
GetTaskInstanceResponse,
59+
GetMappedTaskInstanceData,
60+
GetMappedTaskInstanceResponse,
5961
DeleteVariableData,
6062
DeleteVariableResponse,
6163
GetVariableData,
@@ -874,6 +876,38 @@ export class TaskInstanceService {
874876
},
875877
});
876878
}
879+
880+
/**
881+
* Get Mapped Task Instance
882+
* Get task instance.
883+
* @param data The data for the request.
884+
* @param data.dagId
885+
* @param data.dagRunId
886+
* @param data.taskId
887+
* @param data.mapIndex
888+
* @returns TaskInstanceResponse Successful Response
889+
* @throws ApiError
890+
*/
891+
public static getMappedTaskInstance(
892+
data: GetMappedTaskInstanceData,
893+
): CancelablePromise<GetMappedTaskInstanceResponse> {
894+
return __request(OpenAPI, {
895+
method: "GET",
896+
url: "/public/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/{map_index}",
897+
path: {
898+
dag_id: data.dagId,
899+
dag_run_id: data.dagRunId,
900+
task_id: data.taskId,
901+
map_index: data.mapIndex,
902+
},
903+
errors: {
904+
401: "Unauthorized",
905+
403: "Forbidden",
906+
404: "Not Found",
907+
422: "Validation Error",
908+
},
909+
});
910+
}
877911
}
878912

879913
export class VariableService {

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

+36
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,15 @@ export type GetTaskInstanceData = {
827827

828828
export type GetTaskInstanceResponse = TaskInstanceResponse;
829829

830+
export type GetMappedTaskInstanceData = {
831+
dagId: string;
832+
dagRunId: string;
833+
mapIndex: number;
834+
taskId: string;
835+
};
836+
837+
export type GetMappedTaskInstanceResponse = TaskInstanceResponse;
838+
830839
export type DeleteVariableData = {
831840
variableKey: string;
832841
};
@@ -1528,6 +1537,33 @@ export type $OpenApiTs = {
15281537
};
15291538
};
15301539
};
1540+
"/public/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/{map_index}": {
1541+
get: {
1542+
req: GetMappedTaskInstanceData;
1543+
res: {
1544+
/**
1545+
* Successful Response
1546+
*/
1547+
200: TaskInstanceResponse;
1548+
/**
1549+
* Unauthorized
1550+
*/
1551+
401: HTTPExceptionResponse;
1552+
/**
1553+
* Forbidden
1554+
*/
1555+
403: HTTPExceptionResponse;
1556+
/**
1557+
* Not Found
1558+
*/
1559+
404: HTTPExceptionResponse;
1560+
/**
1561+
* Validation Error
1562+
*/
1563+
422: HTTPValidationError;
1564+
};
1565+
};
1566+
};
15311567
"/public/variables/{variable_key}": {
15321568
delete: {
15331569
req: DeleteVariableData;

0 commit comments

Comments
 (0)