Skip to content

Commit d07ee04

Browse files
committed
Add unit test
1 parent 4cc53f0 commit d07ee04

File tree

2 files changed

+19
-1
lines changed
  • airflow-core
    • src/airflow/api_fastapi/core_api/routes/public
    • tests/unit/api_fastapi/core_api/routes/public

2 files changed

+19
-1
lines changed

airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def update_xcom_entry(
361361
status.HTTP_400_BAD_REQUEST, f"Couldn't serialise the XCom with key: `{xcom_key}`"
362362
) from e
363363

364-
# Re-fetch after set (delete + insert) to get fresh object for response
364+
# Fetch after setting, to get fresh object for response
365365
xcom_entry = session.scalar(xcom_query)
366366
return XComResponseNative.model_validate(xcom_entry)
367367

airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_xcom.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,21 @@ def test_patch_xcom_entry_with_slash_key(self, test_client, session):
845845
assert response.json()["key"] == slash_key
846846
assert response.json()["value"] == new_value
847847
check_last_log(session, dag_id=TEST_DAG_ID, event="update_xcom_entry", logical_date=None)
848+
849+
def test_patch_xcom_preserves_int_type(self, test_client, session):
850+
"""Test scenario described in #59032: if existing XCom value type is int,
851+
after patching with different value, it should still be int in the API response.
852+
"""
853+
key = "int_type_xcom"
854+
# Create with int value
855+
self._create_xcom(key, 42)
856+
patch_value = 100
857+
response = test_client.patch(
858+
f"/dags/{TEST_DAG_ID}/dagRuns/{run_id}/taskInstances/{TEST_TASK_ID}/xcomEntries/{key}",
859+
json={"value": patch_value},
860+
)
861+
assert response.status_code == 200
862+
data = response.json()
863+
assert data["value"] == patch_value
864+
assert isinstance(data["value"], int), f"Expected int type but got {type(data['value'])}"
865+
check_last_log(session, dag_id=TEST_DAG_ID, event="update_xcom_entry", logical_date=None)

0 commit comments

Comments
 (0)