Skip to content

Added last_asset_event_id and last_asset_event_timestamp to the AssetResponse #50060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jroachgolf84
Copy link
Contributor

This pull request adds the last_asset_event_id and last_asset_event_timestamp fields to the AssetResponse model, and thus, the /assets endpoint. The original use-case was to make the Asset list view sortable by the last Asset Event. However, there is a much larger use-case at play here; the ability to easily determine the timestamp for the last Asset Event for a certain Asset. This is especially applicable for Asset Watchers.

By default, the last_asset_event_id and last_asset_event_timestamp fields are returned as null. It's not until the first Asset Event that these fields are populated.

Unit-tests were added/updated for all changes made.

related: #47164

@boring-cyborg boring-cyborg bot added area:airflow-ctl area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers. labels May 1, 2025
@jroachgolf84
Copy link
Contributor Author

@pierrejeambrun, @bbovenzi, #49994 closed in favor of this PR.

Comment on lines 142 to 147
AssetEvent.asset_id, # The ID of the Asset, which we'll need to JOIN to the AssetModel
func.max(AssetEvent.id).label("last_asset_event_id"), # The ID of the last AssetEvent
func.max(AssetEvent.timestamp).label("last_asset_event_timestamp"),
)
.group_by(AssetEvent.asset_id)
.subquery()
Copy link
Contributor

@bbovenzi bbovenzi May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure we're actually selecting the latest timestamp here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify that a bit more? Is the thought here that the max AssetEvent.id might not have the latest timestamp?

There is a unit-test validating this - would you just approach this with a self-JOIN?

…f max(AssetEvent.id) has the max(AssetEvent.timestamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:airflow-ctl area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants