shubhamraj-git commented on code in PR #46042:
URL: https://github.com/apache/airflow/pull/46042#discussion_r1931547022


##########
airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -141,3 +143,80 @@ def get_xcom_entries(
     query = query.order_by(XCom.dag_id, XCom.task_id, XCom.run_id, 
XCom.map_index, XCom.key)
     xcoms = session.scalars(query)
     return XComCollection(xcom_entries=xcoms, total_entries=total_entries)
+
+
+@xcom_router.post(
+    "",
+    status_code=status.HTTP_201_CREATED,
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_400_BAD_REQUEST,
+            status.HTTP_404_NOT_FOUND,
+        ]
+    ),
+)
+def create_xcom_entry(
+    dag_id: str,
+    task_id: str,
+    dag_run_id: str,
+    request_body: XComCreateRequest,
+    session: SessionDep,
+    request: Request,
+) -> XComCreateResponse:
+    """Create an XCom entry."""
+    # Validate DAG ID
+    dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
+    if not dag:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, f"Dag with id {dag_id} 
was not found")
+
+    # Validate Task ID
+    if not dag.get_task(task_id):
+        raise HTTPException(
+            status.HTTP_404_NOT_FOUND, f"Task with ID: `{task_id}` not found 
in DAG: `{dag_id}`"
+        )
+
+    # Validate DAG Run ID
+    dag_run = dag.get_dagrun(dag_run_id, session)
+    if not dag_run:
+        raise HTTPException(
+            status.HTTP_404_NOT_FOUND, f"DAG Run with ID: `{dag_run_id}` not 
found for DAG: `{dag_id}`"
+        )
+
+    # Check existing XCom
+    if XCom.get_one(
+        key=request_body.key,
+        task_id=task_id,
+        dag_id=dag_id,
+        run_id=dag_run_id,
+        map_index=request_body.map_index,
+        session=session,
+    ):
+        raise HTTPException(
+            status_code=status.HTTP_409_CONFLICT,
+            detail=f"The XCom with key: `{request_body.key}` with mentioned 
task instance already exists.",
+        )

Review Comment:
   I updated the description. This PR only focuses on creation of Xcom, Sorry 
for the over description.



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