Execution API set_xcom endpoint returns non-RFC 9457 error for invalid value
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 17.8k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 472
Description
### Under which category would you file this issue?
Airflow Core
### Apache Airflow version
main
### What happened and how to reproduce it?
**Issue Description**
In the Task Execution API, when a worker attempts to set an XCom via the `set_xcom` endpoint and the underlying `XComModel.set()` raises a `ValueError` (for example, if the DAG run or task instance cannot be resolved), the API currently rejects the request and raises an `HTTPException` with a `404 Not Found` status.
However, the `detail` returned is just the raw exception string:
`raise HTTPException(status.HTTP_404_NOT_FOUND, str(e))`
This violates the Airflow RFC 9457 error response requirements for the Execution API, which mandate that domain-layer exceptions should be caught and returned as structured detail schemas (e.g., `{"reason": "...", "message": "..."}`).
**Steps to reproduce:**
1. Send a POST request to `/execution/xcoms/{dag_id}/{run_id}/{task_id}/{key}` with parameters that cause `XComModel.set()` to raise a `ValueError`.
2. Observe the 404 response payload format and see that it is just a plain string instead of a valid RFC 9457 dictionary.
### What you think should happen instead?
The exception handler should return an RFC 9457 compliant detail dictionary, for example:
```python
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail={"reason": "not_found", "message": str(e)},
)
```
### Operating System
Not Applicable
### Deployment
None
### Apache Airflow Provider(s)
_No response_
### Versions of Apache Airflow Providers
_No response_
### Official Helm Chart version
Not Applicable
### Kubernetes Version
Not Applicable
### Helm Chart configuration
Not Applicable
### Docker Image customizations
Not Applicable
### Anything else?
_No response_
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
Contributor guide
Research direction
Start at the Task Execution API set_xcom endpoint and trace how ValueError from XComModel.set() is converted into the 404 response. Confirm the response detail is an RFC 9457-compatible dictionary containing reason and message, and reproduce the invalid DAG run or task instance case to verify the payload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100