AntonioBergonzi commented on code in PR #68244:
URL: https://github.com/apache/airflow/pull/68244#discussion_r3441647631


##########
airflow-core/src/airflow/models/trigger.py:
##########
@@ -252,10 +252,12 @@ def clean_unused(cls, *, session: Session = NEW_SESSION) 
-> None:
         # Get all triggers that have no task instances, assets, or callbacks 
depending on them and delete them
         ids = (
             select(cls.id)
-            .where(~cls.assets.any(), ~cls.callback.has())
-            .join(TaskInstance, cls.id == TaskInstance.trigger_id, 
isouter=True)
-            .group_by(cls.id)
-            .having(func.count(TaskInstance.trigger_id) == 0)
+            .where(
+                ~cls.assets.any(),
+                ~cls.callback.has(),
+                ~cls.task_instance.has(),
+            )
+            .with_for_update(skip_locked=True)
         )

Review Comment:
   Thanks for the review!
   Addressed in 
https://github.com/apache/airflow/pull/68244/changes/ab4776829abdb8c783ac919fba8f0206bc448259,
 I used the helper and scoped the locking to the trigger table. 
   



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