dkranchii opened a new pull request, #67489:
URL: https://github.com/apache/airflow/pull/67489
The `/structure/structure_data` endpoint calls `get_upstream_assets()` to
walk the serialized Dag's `asset_expression`. If the stored expression contains
an unknown key (anything other than `any` / `all`) or an unknown asset type
(anything other than `asset` / `asset-alias` / `asset-name-ref` /
`asset-uri-ref`), `get_upstream_assets()` raises `TypeError("Unsupported type:
...")` at `services/ui/structure.py:69` or `:102`.
The exception escaped uncaught and FastAPI returned a generic `{"detail":
"Internal Server Error"}` response body with no context about *which* Dag
triggered it. Operators had to dig through server logs to identify the broken
Dag — a frustrating debugging loop for a multi-Dag deployment.
This wraps the call in `try/except TypeError` and re-raises as
`HTTPException(500)` with a detail message identifying the Dag id and version.
It remains a 500 because the underlying issue is genuinely server-side
stored-data corruption (not bad client input — the request is valid). The
improvement is the response body: it's now controlled, documented, and
debuggable.
### Before
```
GET /structure/structure_data?dag_id=foo&external_dependencies=True → 500
Internal Server Error
{"detail": "Internal Server Error"}
```
### After
```
GET /structure/structure_data?dag_id=foo&external_dependencies=True → 500
Internal Server Error
{"detail": "Malformed asset_expression in Dag 'foo' version 3: Unsupported
type: dict_keys(['weird-op'])"}
```
### Tests
Adds
`TestStructureDataEndpoint::test_should_return_500_on_malformed_asset_expression`
which mocks `get_upstream_assets` to raise `TypeError` and asserts the
response surfaces a 500 with a detail message that names the Dag and includes
the wrapped error.
### Related
- AGENTS.md rule added in #67221: *"Translate domain-layer exceptions to
HTTPException at FastAPI route boundaries."* This PR conforms to that rule by
replacing an uncaught domain exception with a controlled `HTTPException`
response.
- Sibling PR: #67363 addressed the same class of bug in `ui/dags.py`.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — (Cursor) used for review and verify.
--
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]