manipatnam commented on code in PR #72054:
URL: https://github.com/apache/airflow/pull/72054#discussion_r4739526069
##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -849,8 +849,14 @@ def get_queued_dag_runs_to_set_running(cls, session:
Session) -> ScalarResult[Da
# capacity for 1. this could be improved.
coalesce(running_drs.c.num_running, text("0"))
< coalesce(Backfill.max_active_runs, DagModel.max_active_runs),
- # don't set paused dag runs as running
- not_(coalesce(cast("ColumnElement[bool]", Backfill.is_paused),
False)),
+ # don't set paused dag runs as running, but a completed
backfill's
+ # is_paused flag is stale: a run cleared after the backfill was
+ # cancelled (cancel sets is_paused=True and completed_at) must
still
+ # be schedulable, otherwise it is stuck in queued forever.
+ or_(
+ Backfill.completed_at.isnot(None),
Review Comment:
Good catch, thanks. Added the guard in 20bf8b35f6: `cancel_backfill` now
returns 409 while the backfill has no `BackfillDagRun` rows yet, so a cancel
can no longer land between the `Backfill` commit and the runs' commit. It's
covered by `test_cancel_backfill_conflict_while_initializing`.
I didn't add a time cutoff like the one in `_mark_backfills_complete`. That
function already marks a backfill complete if it has no associations after 2
minutes, so a backfill whose creation failed doesn't stay uncancellable.
Without a cutoff, a backfill that takes a long time to create can't hit the
race either.
One case this doesn't cover: runs orphaned by this race before upgrading
(queued under a paused, completed backfill) would be started by the new
scheduler filter. That needs a cancel inside the creation window, so I expect
it to be very rare, and I've left it out of this PR. If you'd rather close it
too, I see two options: a migration that fails those runs, or detaching a
cleared run from its completed backfill on clear instead of relaxing the
scheduler filter. Happy to switch to either.
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @manipatnam 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]