pierrejeambrun commented on code in PR #49994:
URL: https://github.com/apache/airflow/pull/49994#discussion_r2068711201


##########
airflow-core/src/airflow/models/asset.py:
##########
@@ -276,6 +276,19 @@ class AssetModel(Base):
     producing_tasks = relationship("TaskOutletAssetReference", 
back_populates="asset")
     triggers = relationship("Trigger", 
secondary=asset_trigger_association_table, back_populates="assets")
 
+    # ForeignKey("asset_event.id") -> this was originally in the 
last_asset_event_id definition
+    # The default value should be None. When an Asset is defined, it is not 
yet tied to an AssetEvent
+    last_asset_event_id = Column(Integer, default=None)
+    last_asset_event_timestamp = Column(UtcDateTime, default=None)
+
+    last_event = relationship(
+        "AssetEvent",
+        primaryjoin="AssetModel.last_asset_event_id == foreign(AssetEvent.id)",
+        viewonly=True,
+        lazy="select",
+        uselist=False,
+    )

Review Comment:
   You'll need a subquery / CTE to get the latest asset event id and timestamp 
per asset_id, then outer join that table with that query there yes.
   
https://github.com/apache/airflow/blob/27f559e87170b9059f018206bf6dbbaa76529afa/airflow/api_fastapi/core_api/routes/public/assets.py#L351



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