ColtenOuO opened a new pull request, #72599:
URL: https://github.com/apache/airflow/pull/72599
### Summary
`GET /assets/{asset_id}` resolves the asset's "last asset event" in two
steps: it first computes `max(AssetEvent.timestamp)` for the asset, then
re-queries the events matching that timestamp with `.one_or_none()`. Nothing
guarantees that timestamp is unique — an asset can be updated by several tasks
within the same clock tick, and the timestamp column has no uniqueness
constraint. When two or more events tie on the newest timestamp, the second
query returns multiple rows and SQLAlchemy raises `MultipleResultsFound`, which
surfaces to the caller as `500 Internal Server Error` instead of the asset
payload.
This is the same class of bug fixed for `/ui/assets` in #71047 (that fix
broke the tie with `max(id)` inside the aggregate query), but the public API
endpoint was not covered by it and still carries the original two-step lookup.
### Changes
- `airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py`:
replace the `max(timestamp)` subquery + `.one_or_none()` pair with a single
ordered query — `ORDER BY timestamp DESC, id DESC LIMIT 1` — so exactly one
event is selected and ties are broken deterministically on the highest id,
matching the `/ui/assets` behaviour.
-
`airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py`:
add
`TestGetAssetEndpoint::test_should_respond_200_with_tied_last_event_timestamps`,
which creates two events for the same asset with identical timestamps and
asserts the endpoint returns `200` with the higher event id as
`last_asset_event`. The test returns `500` without the source change.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5)
--
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]