Kaap10 opened a new pull request, #73753:
URL: https://github.com/apache/airflow/pull/73753

   ### Description
   
   While exploring the FastAPI state store endpoints under 
`airflow-core/src/airflow/api_fastapi/core_api/routes/public/`, I noticed that 
domain-level exceptions raised by the underlying metastore backend were not 
being intercepted at the route handler layer. Specifically:
   
   1. **In Asset State Store (`PUT /{key:path}`)**: If 
`_get_db_backend().set_asset_state_store(...)` encounters invalid input/payload 
parameters, it raises a domain `ValueError`. Because this was unhandled in the 
route handler, FastAPI was propagating it as an unhandled `500 Internal Server 
Error` rather than an informative client error.
   2. **In Task State Store (`PATCH /{key:path}`)**: When modifying an existing 
key via `_get_db_backend().set(...)`, a missing execution scope (such as a 
non-existent `DagRun`) raises a `ValueError`. This was similarly bubbling up as 
an unexpected `500` response.
   
   Per Airflow's coding standards ("*Translate domain-layer exceptions to 
HTTPException at FastAPI route boundaries*"), this PR wraps both calls in 
explicit `try ... except ValueError` blocks:
   - In `asset_state_store.py`: Translates `ValueError` $\rightarrow$ 
`HTTPException(400, detail=str(e))` and registers `400 Bad Request` in the 
OpenAPI exception spec documentation.
   - In `task_state_store.py`: Translates `ValueError` $\rightarrow$ 
`HTTPException(404, detail=str(e))` matching the REST API error conventions.
   - Added corresponding unit tests in 
[`test_asset_state_store.py`](file:///c:/Users/vardh/airflow/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_asset_state_store.py)
 and 
[`test_task_state_store.py`](file:///c:/Users/vardh/airflow/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_state_store.py)
 to assert and prevent future regressions.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Antigravity
   
   Generated-by: Antigravity following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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