jroachgolf84 commented on code in PR #50060:
URL: https://github.com/apache/airflow/pull/50060#discussion_r2072427068


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -385,16 +434,43 @@ def get_asset(
     session: SessionDep,
 ) -> AssetResponse:
     """Get an asset."""
+    # Build a subquery to be used to retrieve the latest AssetEvent by 
matching timestamp
+    last_asset_event = (
+        select(func.max(AssetEvent.timestamp)).where(AssetEvent.asset_id == 
asset_id).scalar_subquery()
+    )
+
+    # Now, find the latest AssetEvent details using the subquery from above
+    asset_event_rows = session.execute(
+        select(AssetEvent.asset_id, AssetEvent.id, AssetEvent.timestamp).where(
+            AssetEvent.asset_id == asset_id, AssetEvent.timestamp == 
last_asset_event
+        )
+    )
+
+    # Retrieve the Asset; there should only be one for that asset_id
     asset = session.scalar(
         select(AssetModel)
         .where(AssetModel.id == asset_id)
         .options(joinedload(AssetModel.consuming_dags), 
joinedload(AssetModel.producing_tasks))
     )
 
+    last_asset_event_id, last_asset_event_timestamp = None, None
+
+    # Pull the event ID and timestamp from the asset_event_query
+    for row in asset_event_rows:
+        _, last_asset_event_id, last_asset_event_timestamp = row
+        break  # There should only be one record, but be proactive
+
     if asset is None:
         raise HTTPException(status.HTTP_404_NOT_FOUND, f"The Asset with ID: 
`{asset_id}` was not found")
 
-    return AssetResponse.model_validate(asset)
+    return AssetResponse.model_validate(
+        {
+            **asset.__dict__,
+            "aliases": asset.aliases,
+            "last_asset_event_id": last_asset_event_id,

Review Comment:
   Resolved!



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