justinpakzad commented on code in PR #59874:
URL: https://github.com/apache/airflow/pull/59874#discussion_r3724667826


##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -652,6 +653,27 @@ def delete(
         # decouple from the server response string
         return OKResponse(ok=True)
 
+    def delete_all(
+        self,
+        dag_id: str,
+        run_id: str,
+        task_id: str | None = None,
+        key: str | None = None,
+        map_index: int | None = None,
+    ) -> XComDeleteCountResult:
+        """Bulk delete XCom values via the API server."""
+        params: dict[str, str | int] = {}
+
+        if map_index is not None:
+            params["map_index"] = map_index
+        if task_id is not None:
+            params["task_id"] = task_id
+        if key is not None:
+            params["key"] = key
+
+        resp = self.client.delete(url=f"xcoms/{dag_id}/{run_id}", 
params=params)
+        return XComDeleteCountResult(count=resp.json()["count"])

Review Comment:
   I've updated the docstring to state that the returned count is best effort 
and retried request can report fewer rows than were actually deleted.



##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py:
##########
@@ -482,3 +482,36 @@ def delete_xcom(
     )
     session.execute(query)
     return {"message": f"XCom with key: {key} successfully deleted."}
+
+
[email protected](
+    "/{dag_id}/{run_id}",
+    description="Bulk delete Xcom values.",
+)
+def bulk_delete_xcoms(
+    session: SessionDep,
+    dag_id: str,
+    run_id: str,
+    task_id: Annotated[str | None, Query()] = None,
+    key: Annotated[str | None, Query()] = None,
+    map_index: Annotated[int | None, Query()] = None,
+):
+    """Bulk delete Xcom values."""
+    query = delete(XComModel).where(
+        XComModel.dag_id == dag_id,
+        XComModel.run_id == run_id,
+    )
+
+    if task_id is not None:
+        query = query.where(XComModel.task_id == task_id)
+
+    if key is not None:
+        query = query.where(XComModel.key == key)
+
+    if map_index is not None:
+        query = query.where(XComModel.map_index == map_index)
+
+    result = session.execute(query)
+    count = getattr(result, "rowcount", 0)

Review Comment:
   Removed the `getattr`, route returns an `int` directly. Added a cast because 
session.execute() returns Result[Any], which has no rowcount.



##########
airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_09_09.py:
##########
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from cadwyn import VersionChange, endpoint
+
+
+class AddXcomBulkDeleteEndpoint(VersionChange):
+    """Add XCom bulk delete endpoint."""
+
+    description = __doc__
+
+    instructions_to_migrate_to_previous_version = (
+        endpoint("/xcoms/{dag_id}/{run_id}", ["DELETE"]).didnt_exist,

Review Comment:
   I've added a test following the same pattern as 
`versions/v2026_06_30/test_variables.py`



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