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


##########
airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -335,3 +337,40 @@ def get_task_instances(
         ],
         total_entries=total_entries,
     )
+
+
+@task_instances_router.get(
+    "/{task_id}/tries/{task_try_number}",
+    responses=create_openapi_http_exception_doc(
+        [status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN, 
status.HTTP_404_NOT_FOUND]
+    ),
+)
+async def get_task_instance_try_details(
+    dag_id: str,
+    dag_run_id: str,
+    task_id: str,
+    task_try_number: int,
+    session: Annotated[Session, Depends(get_session)],
+    map_index: int = -1,
+) -> TaskInstanceHistoryResponse:
+    """Get task instance details by try number."""
+
+    def _query(TI):
+        query = select(TI).where(
+            TI.dag_id == dag_id,
+            TI.run_id == dag_run_id,
+            TI.task_id == task_id,
+            TI.try_number == task_try_number,
+            TI.map_index == map_index,
+        )
+
+        task_instance = session.scalar(query)
+        return task_instance
+
+    result = _query(TI) or _query(TIH)
+    if result is None:
+        raise HTTPException(
+            status.HTTP_404_NOT_FOUND,
+            f"The Task Instance with dag_id: `{dag_id}`, run_id: 
`{dag_run_id}`, task_id: `{task_id}`, try_number: `{task_try_number}` and 
map_index: `{map_index}` was not found",
+        )
+    return TaskInstanceHistoryResponse.model_validate(result, 
from_attributes=True)

Review Comment:
   As we saw that there was some small differences bestween 
`TaskInstanceHistoryResponse` and `TaskInstanceResponse`, I would say that 
`TaskInstanceHistoryResponse` is the most appropriate.



##########
airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -335,3 +337,40 @@ def get_task_instances(
         ],
         total_entries=total_entries,
     )
+
+
+@task_instances_router.get(
+    "/{task_id}/tries/{task_try_number}",
+    responses=create_openapi_http_exception_doc(
+        [status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN, 
status.HTTP_404_NOT_FOUND]
+    ),
+)
+async def get_task_instance_try_details(
+    dag_id: str,
+    dag_run_id: str,
+    task_id: str,
+    task_try_number: int,
+    session: Annotated[Session, Depends(get_session)],
+    map_index: int = -1,
+) -> TaskInstanceHistoryResponse:
+    """Get task instance details by try number."""
+
+    def _query(TI):
+        query = select(TI).where(
+            TI.dag_id == dag_id,
+            TI.run_id == dag_run_id,
+            TI.task_id == task_id,
+            TI.try_number == task_try_number,
+            TI.map_index == map_index,
+        )
+
+        task_instance = session.scalar(query)
+        return task_instance
+
+    result = _query(TI) or _query(TIH)
+    if result is None:
+        raise HTTPException(
+            status.HTTP_404_NOT_FOUND,
+            f"The Task Instance with dag_id: `{dag_id}`, run_id: 
`{dag_run_id}`, task_id: `{task_id}`, try_number: `{task_try_number}` and 
map_index: `{map_index}` was not found",
+        )
+    return TaskInstanceHistoryResponse.model_validate(result, 
from_attributes=True)

Review Comment:
   As we saw that there was some small differences bestween 
`TaskInstanceHistoryResponse` and `TaskInstanceResponse`, I would say that 
`TaskInstanceHistoryResponse` is the most appropriate. (Those are not fully 
exchangeable)



-- 
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