amoghrajesh commented on code in PR #64220:
URL: https://github.com/apache/airflow/pull/64220#discussion_r2999190093
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -270,27 +269,24 @@ def create_xcom_entry(
)
try:
- value = json.dumps(request_body.value)
- except (ValueError, TypeError):
+ XComModel.set(
+ key=request_body.key,
+ value=request_body.value,
+ dag_id=dag_id,
+ task_id=task_id,
+ run_id=dag_run_id,
+ map_index=request_body.map_index,
+ serialize=False,
+ session=session,
+ )
+ except (ValueError, TypeError) as e:
raise HTTPException(
status.HTTP_400_BAD_REQUEST, f"Couldn't serialise the XCom with
key: `{request_body.key}`"
- )
-
- new = XComModel(
- dag_run_id=dag_run.id,
- key=request_body.key,
- value=value,
- run_id=dag_run_id,
- task_id=task_id,
- dag_id=dag_id,
- map_index=request_body.map_index,
- )
- session.add(new)
- session.flush()
+ ) from e
xcom = session.scalar(
select(XComModel)
- .filter(
+ .where(
Review Comment:
Why this change?
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -340,16 +337,32 @@ def update_xcom_entry(
.limit(1)
.options(joinedload(XComModel.task),
joinedload(XComModel.dag_run).joinedload(DR.dag_model))
)
+ xcom_entry = session.scalar(xcom_query)
if not xcom_entry:
raise HTTPException(
status.HTTP_404_NOT_FOUND,
f"The XCom with key: `{xcom_key}` with mentioned task instance
doesn't exist.",
)
- # Update XCom entry
- xcom_entry.value = json.dumps(patch_body.value)
+ try:
+ XComModel.set(
+ key=xcom_key,
+ value=patch_body.value,
+ dag_id=dag_id,
+ task_id=task_id,
+ run_id=dag_run_id,
+ map_index=patch_body.map_index,
+ serialize=False,
+ session=session,
+ )
+ except (ValueError, TypeError) as e:
+ raise HTTPException(
+ status.HTTP_400_BAD_REQUEST, f"Couldn't serialise the XCom with
key: `{xcom_key}`"
+ ) from e
+ # Re-fetch after set (delete + insert) to get fresh object for response
Review Comment:
```suggestion
# Fetch after setting, to get fresh object for response
```
--
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]