AntonioBergonzi commented on code in PR #68244:
URL: https://github.com/apache/airflow/pull/68244#discussion_r3411946155
##########
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:
I can cherry pick this
https://github.com/AntonioBergonzi/airflow/commit/95b2489ad5561506c70d1e748db8772a701cfaac
in this branch. However I noticed we use with_for_update with skip_locked in
other parts of the code ([in the
scheduler](https://github.com/apache/airflow/blob/b64a0e636d9b693a1a17d6f226e3a78014c13afc/airflow-core/src/airflow/jobs/scheduler_job_runner.py#L2501),
for example)
--
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]