seanghaeli commented on code in PR #77086:
URL: https://github.com/apache/airflow/pull/77086#discussion_r4651705415


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/triggers.py:
##########
@@ -68,12 +68,13 @@ def _sort_null_as_smallest(column: ColumnElement) -> 
list[ColumnElement]:
 
 
 def _build_triggers_select() -> Select:
-    # Only triggers their owner still refers to: the rest are deleted on the 
triggerer's next cleanup. The
-    # kwargs are never returned, so they are not even loaded.
+    # Only triggers their owner still refers to or that are finished and kept 
for the
+    # failure-retention window: the rest are deleted on the triggerer's next 
cleanup.
+    # The kwargs are never returned, so they are not even loaded.
     return (
         select(Trigger)
         .outerjoin(Trigger.triggerer_job)
-        .where(Trigger.owner_still_refers_expression())
+        .where(or_(Trigger.owner_still_refers_expression(), 
Trigger.finished_at.is_not(None)))

Review Comment:
   In Breeze the failed trigger is kept, but the API never shows it. After 
pausing the Dag, the row was there with `finished_at` and its error, yet `GET 
/triggers/{id}` returned 404 and the list left it out. A watcher's trigger is 
only readable through an asset its watchers watch (`PermittedTriggerFilter`), 
and those watcher rows are gone by then. A deferred task's failed trigger is 
dropped too, by `_build_response` once its task instance lets go, so the list 
came back as `{"triggers": [], "total_entries": 1}`. Could the row keep what it 
was used by when it finishes, so the permission check and the response still 
have something to go on, with a test that reads a finished trigger through the 
API?



##########
airflow-core/src/airflow/models/trigger.py:
##########
@@ -688,6 +762,14 @@ def get_sorted_triggers(
         """
         from airflow.models.callback import Callback  # to avoid circular 
import: Callback -> Trigger
 
+        # A finished trigger that regained a reference is live again; let it 
be assigned and run.
+        session.execute(

Review Comment:
   This runs an UPDATE on every triggerer loop (one a loop in Breeze, on 
Postgres and MySQL), just to catch a trigger that got its reference back. Only 
the Dag processor can do that, in `add_asset_trigger_references`, and there it 
usually makes a new trigger anyway: unpausing the Dag gave the watcher a new 
trigger while the old one stayed finished, since existing rows are looked up by 
their encrypted kwargs. Could we clear `finished_at` there, when the reference 
is added, instead?



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