hussein-awala commented on code in PR #72849:
URL: https://github.com/apache/airflow/pull/72849#discussion_r3973795678


##########
airflow-core/src/airflow/models/trigger.py:
##########
@@ -268,6 +268,18 @@ def clean_unused(cls, *, session: Session = NEW_SESSION) 
-> None:
                 
delete(Trigger).where(Trigger.id.in_(ids)).execution_options(synchronize_session=False)
             )
 
+    @staticmethod
+    def _get_deferred_task_instances(trigger_id: int, *, session: Session) -> 
Iterable[TaskInstance]:
+        """Lock and refresh tasks still waiting on this trigger before 
applying its result."""
+        query = (
+            select(TaskInstance)
+            .where(TaskInstance.trigger_id == trigger_id, TaskInstance.state 
== TaskInstanceState.DEFERRED)
+            .order_by(TaskInstance.id)
+            .execution_options(populate_existing=True)
+        )
+        # Wait for concurrent transitions; skipping a locked row would lose 
this result.
+        return session.scalars(with_row_locks(query, session, of=TaskInstance))

Review Comment:
   That's a good point!



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