Copilot commented on code in PR #72849:
URL: https://github.com/apache/airflow/pull/72849#discussion_r3973778064
##########
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:
`with_row_locks()` becomes a no-op when `[scheduler]
use_row_level_locking=False`. That setting supports a single scheduler, but the
scheduler and triggerer still run concurrently, so this configuration retains
the stale-result race this change is intended to fix. This is a correctness
lock rather than a scheduler-HA optimization; acquire it directly and add
coverage with the setting disabled.
---
Drafted-by: GitHub Copilot (no human review before posting)
--
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]