bbovenzi commented on code in PR #71441:
URL: https://github.com/apache/airflow/pull/71441#discussion_r3761483933


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py:
##########
@@ -377,8 +378,19 @@ def get_asset_events(
     # dependency-applied timeout is still active.
     assets_events = session.scalars(assets_event_select).all()
 
+    # An asset event is linked to every dag run that consumed it, so a run 
that consumed several
+    # events would otherwise appear as "triggered" on each one. Only a run's 
most recent consumed
+    # event actually triggers it; the rest were merely included.
+    triggering_event_id_by_run = resolve_triggering_event_ids(assets_events, 
session=session)
+    asset_event_responses = []
+    for event in assets_events:
+        event_response = AssetEventResponse.model_validate(event)
+        for reference, dag_run in zip(event_response.created_dagruns, 
event.created_dagruns):
+            reference.triggering = triggering_event_id_by_run.get(dag_run.id) 
== event.id

Review Comment:
   Why zip instead of actually checking the two ids?



##########
airflow-ctl/src/airflowctl/api/datamodels/generated.py:
##########
@@ -533,6 +533,13 @@ class DagRunAssetReference(BaseModel):
     data_interval_start: Annotated[datetime | None, Field(title="Data Interval 
Start")]
     data_interval_end: Annotated[datetime | None, Field(title="Data Interval 
End")]
     partition_key: Annotated[str | None, Field(title="Partition Key")]
+    triggering: Annotated[
+        bool | None,
+        Field(
+            description="Whether this asset event triggered the referenced dag 
run. Only a run's most recent consumed asset event triggers it; earlier 
consumed events are included in the run but did not trigger it.",
+            title="Triggering",
+        ),
+    ] = True

Review Comment:
   Shouldn't the default be None?



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -282,16 +281,28 @@ def get_upstream_asset_events(
             DagRun.dag_id == dag_id,
             DagRun.run_id == dag_run_id,
         )
-        
.options(joinedload(DagRun.consumed_asset_events).joinedload(AssetEvent.asset))
+        .options(
+            
joinedload(DagRun.consumed_asset_events).joinedload(AssetEvent.asset),
+            
joinedload(DagRun.consumed_asset_events).subqueryload(AssetEvent.created_dagruns),

Review Comment:
   Let's add an N+1 test for this



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