Copilot commented on code in PR #68244:
URL: https://github.com/apache/airflow/pull/68244#discussion_r3404564332
##########
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:
`with_for_update(skip_locked=True)` is applied unconditionally here. This
can generate unsupported SQL (e.g. MySQL < 8 / some MariaDB versions, or when
row-level locking is disabled) and bypasses Airflow's `with_row_locks()` helper
that already handles dialect support and configuration. Consider using
`with_row_locks(..., skip_locked=True)` (and `of=cls`) instead of calling
`with_for_update` directly; set `key_share=False` to keep `FOR UPDATE`
semantics.
--
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]