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


##########
airflow/api_fastapi/core_api/datamodels/task_instances.py:
##########
@@ -150,3 +152,41 @@ class TaskInstanceHistoryCollectionResponse(BaseModel):
 
     task_instances: list[TaskInstanceHistoryResponse]
     total_entries: int
+
+
+class PatchTaskInstanceBody(BaseModel):
+    """Request body for Clear Task Instances endpoint."""
+
+    dry_run: bool = True
+    new_state: str | None = None
+    note: str | None = None
+
+    @model_validator(mode="before")
+    @classmethod
+    def validate_model(cls, data: Any) -> Any:
+        if data.get("note") is None and data.get("new_state") is None:
+            raise ValueError("new_state is required.")
+        return data
+
+    @field_validator("note", mode="before")
+    @classmethod
+    def validate_note(cls, note: str | None) -> str | None:
+        """Validate note."""
+        if note is None:
+            return None
+        if len(note) > 1000:
+            raise ValueError("Note length should not exceed 1000 characters.")

Review Comment:
   This exists natively in pydantic Field. We can use that instead of coding a 
check manually.



##########
airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -482,3 +484,78 @@ def get_mapped_task_instance_try_details(
         map_index=map_index,
         session=session,
     )
+
+
+@task_instances_router.patch(
+    "/{task_id}",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND, 
status.HTTP_400_BAD_REQUEST]),
+)
+@task_instances_router.patch(
+    "/{task_id}/{map_index}",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND, 
status.HTTP_400_BAD_REQUEST]),
+)
+def patch_task_instance(
+    dag_id: str,
+    dag_run_id: str,
+    task_id: str,
+    request: Request,
+    body: PatchTaskInstanceBody,
+    session: Annotated[Session, Depends(get_session)],
+    map_index: int = -1,

Review Comment:
   We are missing the update mask.
   
   You can take a look at others (not all of them are reworked yet), but 
`patch_dag_run` might be close to what you want. 
   
   Also, if `mask` is provided, `None` values should not be ignored but set to 
`None`.



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