pierrejeambrun commented on code in PR #62812:
URL: https://github.com/apache/airflow/pull/62812#discussion_r2907045411


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -847,6 +850,103 @@ def _collect_relatives(run_id: str, direction: 
Literal["upstream", "downstream"]
     )
 
 
+@task_instances_router.patch(
+    "/dagRuns/{dag_run_id}/taskGroupInstances/{group_id}",
+    responses=create_openapi_http_exception_doc(
+        [status.HTTP_404_NOT_FOUND, status.HTTP_400_BAD_REQUEST, 
status.HTTP_409_CONFLICT],
+    ),
+    dependencies=[
+        Depends(action_logging()),
+        Depends(requires_access_dag(method="PUT", 
access_entity=DagAccessEntity.TASK_INSTANCE)),
+    ],
+    operation_id="patch_task_group_instances",
+)
+def patch_task_group_instances(
+    dag_id: str,
+    dag_run_id: str,
+    group_id: str,
+    dag_bag: DagBagDep,
+    body: PatchTaskGroupBody,
+    session: SessionDep,
+    user: GetUserDep,
+) -> TaskInstanceCollectionResponse:
+    """Update the state of all task instances in a task group."""
+    _patch_task_group_state(
+        dag_id=dag_id,
+        dag_run_id=dag_run_id,
+        group_id=group_id,
+        body=body,
+        dag_bag=dag_bag,
+        user=user,
+        session=session,
+    )
+
+    # Collect all TIs for the task group to build the response
+    dag = get_latest_version_of_dag(dag_bag, dag_id, session)
+    task_ids = _get_task_group_task_ids(dag, group_id)
+    tis = (
+        session.scalars(
+            select(TI)
+            .where(TI.dag_id == dag_id, TI.run_id == dag_run_id, 
TI.task_id.in_(task_ids))
+            .join(TI.dag_run)
+            .options(joinedload(TI.rendered_task_instance_fields))
+            .options(joinedload(TI.dag_version))
+            
.options(joinedload(TI.dag_run).options(joinedload(DagRun.dag_model)))
+        )
+        .unique()
+        .all()

Review Comment:
   This query could probably be avoided. we are fetching from the DB at 
multiple places.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to