kaxil commented on code in PR #69403:
URL: https://github.com/apache/airflow/pull/69403#discussion_r3625704983


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -860,6 +861,43 @@ def ti_skip_downstream(
     log.info("Downstream tasks skipped", tasks_skipped=getattr(result, 
"rowcount", 0))
 
 
+@ti_id_router.patch(
+    "/{task_instance_id}/dag-run-note",
+    status_code=status.HTTP_204_NO_CONTENT,
+    responses=create_openapi_http_exception_doc(
+        [
+            (status.HTTP_404_NOT_FOUND, "Task Instance not found"),
+            (HTTP_422_UNPROCESSABLE_CONTENT, "Invalid payload for the DagRun 
note update"),
+        ]
+    ),
+)
+def update_dag_run_note(
+    task_instance_id: UUID,
+    body: DagRunNoteUpdatePayload,
+    session: SessionDep,
+) -> None:
+    """Update the note for the DagRun associated with this task instance."""
+    bind_contextvars(ti_id=str(task_instance_id))
+
+    dag_run = session.scalar(
+        select(DR)
+        .join(TI, and_(TI.dag_id == DR.dag_id, TI.run_id == DR.run_id))
+        .options(joinedload(DR.dag_run_note))
+        .where(TI.id == task_instance_id)
+    )
+    if dag_run is None:
+        raise HTTPException(
+            status_code=status.HTTP_404_NOT_FOUND,
+            detail={"reason": "not_found", "message": "Task Instance not 
found"},
+        )
+
+    if dag_run.dag_run_note is None:

Review Comment:
   This reimplements the set/update/clear logic that `patch_dag_run_note` in 
`core_api/services/public/dag_run.py` already has, and the two diverge on 
clearing. That helper deletes the note row on an empty note (`if note == "": 
dag_run.dag_run_note = None`), whereas here clearing with `note=None` (or `""`) 
leaves or creates a `dag_run_note` row with NULL/empty content. So a run 
cleared from runtime still has a `dag_run_note` row, unlike one cleared from 
the UI. Could this reuse `patch_dag_run_note` (with an optional user_id) so the 
two note-editing paths stay consistent?



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