ashb commented on code in PR #74222:
URL: https://github.com/apache/airflow/pull/74222#discussion_r4182305907


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py:
##########
@@ -488,15 +534,49 @@ def delete_xcom(
     run_id: str,
     task_id: str,
     key: Annotated[str, Path(min_length=1)],
+    request: Request,
     map_index: Annotated[int, Query()] = -1,
+    token=CurrentTIToken,
 ):
     """Delete a single XCom Value."""
-    query = delete(XComModel).where(
-        XComModel.key == key,
-        XComModel.run_id == run_id,
-        XComModel.task_id == task_id,
-        XComModel.dag_id == dag_id,
-        XComModel.map_index == map_index,
+    owner = _writer_id(
+        token.id,
+        dag_id=dag_id,
+        run_id=run_id,
+        task_id=task_id,
+        map_index=map_index,
+        request=request,
+        session=session,
+    )
+    XComModel.delete_for_attempts(
+        producer_ids=select(TaskInstance.id).where(TaskInstance.id == owner),
+        key=key,
+        session=session,
     )
-    session.execute(query)
     return {"message": f"XCom with key: {key} successfully deleted."}
+
+
+def _writer_id(
+    attempt_id: UUID,
+    *,
+    dag_id: str,
+    run_id: str,
+    task_id: str,
+    map_index: int,
+    request: Request,
+    session: SessionDep,
+) -> UUID:
+    query = select(TaskInstance.id).where(
+        TaskInstance.dag_id == dag_id,
+        TaskInstance.run_id == run_id,
+        TaskInstance.task_id == task_id,
+        TaskInstance.map_index == map_index,
+    )
+    if request.scope.get(_IN_PROCESS_NON_TI_CALLER):
+        query = query.where(TaskInstance.working_set.is_(True))
+    else:
+        query = query.where(TaskInstance.id == attempt_id)
+    owner = session.scalar(query)
+    if owner is None:
+        raise HTTPException(status.HTTP_403_FORBIDDEN, detail={"reason": 
"attempt_coordinates_mismatch"})

Review Comment:
   Yes, just noticed this too (and the tests caught it thankfully). Not 
intended, am fixing.



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