FrancescoCastaldi commented on code in PR #77633:
URL: https://github.com/apache/airflow/pull/77633#discussion_r4719570775
##########
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_xcoms.py:
##########
@@ -1841,6 +1841,33 @@ def test_xcom_dag_result(self, client,
create_task_instance, authenticate_as, se
dag_result = XComModelV2.get_for_attempt(ti.id, "return_value",
session=session).dag_result
assert dag_result is True
+ def test_set_xcom_value_error_returns_rfc9457(self, client,
create_task_instance, authenticate_as, session):
+ """
+ When XComModel.set_for_attempt raises ValueError the endpoint must
return a 404
+ response whose ``detail`` field is an RFC 9457-compliant dict
containing the
+ ``reason`` and ``message`` keys, not a bare string.
+
+ Regression test for issue #70044.
+ """
+ ti = create_task_instance()
+ session.commit()
+ authenticate_as(ti)
+
+ with patch(
+
"airflow.api_fastapi.execution_api.routes.xcoms.XComModel.set_for_attempt",
+ side_effect=ValueError("unknown task instance id"),
+ ):
+ response = client.post(
+
f"/execution/xcoms/{ti.dag_id}/{ti.run_id}/{ti.task_id}/xcom_1",
+ json='"value"',
+ )
+
+ assert response.status_code == 404
+ detail = response.json()["detail"]
+ assert isinstance(detail, dict), f"detail must be a dict (RFC 9457),
got {type(detail)}: {detail!r}"
+ assert detail["reason"] == "not_found"
+ assert detail["message"] == "unknown task instance id"
Review Comment:
Thanks for the review and suggestion. Updated in commit `e9bd5fa72a`:
- Renamed the test to `test_set_xcom_handles_value_error` and shortened the
docstring to a single line.
- Switched the request body to `json="value"` and consolidated the
assertions on `response.json()["detail"]`.
- Verified locally with `prek` (`ruff`, `ruff-format`,
`check-merge-conflict`, `end-of-file-fixer`, `trailing-whitespace`,
`mixed-line-ending`, `check-for-inclusive-language`), `mypy`, and `pytest` (`23
passed` in `TestXComsSetEndpoint`).
--
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]