pierrejeambrun commented on code in PR #43675:
URL: https://github.com/apache/airflow/pull/43675#discussion_r1844182536
##########
airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -331,3 +333,38 @@ 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_404_NOT_FOUND]),
+)
+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):
Review Comment:
Also you can add typing (param and return type) Select
##########
airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -331,3 +333,38 @@ 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_404_NOT_FOUND]),
+)
+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):
Review Comment:
```suggestion
def _query(TI):
```
```suggestion
def _query(orm_object: Base):
```
`orm_object` is more explicit.
##########
airflow/api_fastapi/core_api/datamodels/task_instances.py:
##########
@@ -83,3 +83,39 @@ class TaskDependencyCollectionResponse(BaseModel):
"""Task scheduling dependencies collection serializer for responses."""
dependencies: list[TaskDependencyResponse]
+
+
+class TaskInstanceHistoryResponse(BaseModel):
+ """TaskInstanceHistory serializer for responses."""
+
+ model_config = ConfigDict(populate_by_name=True)
+
+ task_id: str
+ dag_id: str
+ run_id: str = Field(alias="dag_run_id")
+ map_index: int
+ start_date: datetime | None
+ end_date: datetime | None
+ duration: float | None
+ state: TaskInstanceState | None
+ try_number: int
+ max_tries: int
+ task_display_name: str
+ hostname: str | None
+ unixname: str | None
+ pool: str
+ pool_slots: int
+ queue: str | None
+ priority_weight: int | None
+ operator: str | None
+ queued_dttm: datetime | None = Field(alias="queued_when")
+ pid: int | None
+ executor: str | None
+ executor_config: Annotated[str, BeforeValidator(str)]
+
+
+class TaskInstanceHistoryCollectionResponse(BaseModel):
+ """Task Instance Collection serializer for responses."""
Review Comment:
docstring need update.
##########
tests/api_fastapi/core_api/routes/public/test_task_instances.py:
##########
@@ -1127,3 +1128,174 @@ def test_should_respond_dependencies_mapped(self,
test_client, session):
"print_the_context/0/dependencies",
)
assert response.status_code == 200, response.text
+
+
+class TestGetTaskInstanceTry(TestTaskInstanceEndpoint):
+ def test_should_respond_200(self, test_client, session):
+ self.create_task_instances(session, task_instances=[{"state":
State.SUCCESS}], with_ti_history=True)
+ response = test_client.get(
+
"/public/dags/example_python_operator/dagRuns/TEST_DAG_RUN_ID/taskInstances/print_the_context/tries/1"
+ )
+ assert response.status_code == 200
+ assert response.json() == {
+ "dag_id": "example_python_operator",
+ "duration": 10000.0,
+ "end_date": "2020-01-03T00:00:00Z",
+ "executor": None,
+ "executor_config": "{}",
+ "hostname": "",
+ "map_index": -1,
+ "max_tries": 0,
+ "operator": "PythonOperator",
+ "pid": 100,
+ "pool": "default_pool",
+ "pool_slots": 1,
+ "priority_weight": 9,
+ "queue": "default_queue",
+ "queued_when": None,
+ "start_date": "2020-01-02T00:00:00Z",
+ "state": "success",
+ "task_id": "print_the_context",
+ "task_display_name": "print_the_context",
+ "try_number": 1,
+ "unixname": getuser(),
+ "dag_run_id": "TEST_DAG_RUN_ID",
+ }
+
Review Comment:
Any reason why
`test_should_respond_200_with_mapped_task_at_different_try_numbers` was not
moved over ?
--
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]