shahar1 commented on code in PR #77157:
URL: https://github.com/apache/airflow/pull/77157#discussion_r4620611828
##########
airflow-core/src/airflow/models/backfill.py:
##########
@@ -315,7 +315,10 @@ def _get_latest_dag_run_row_query(*, dag_id: str, info:
DagRunInfo):
stmt = stmt.where(DagRun.partition_date == info.partition_date)
if info.logical_date is not None:
stmt = stmt.where(DagRun.logical_date == info.logical_date)
- stmt = stmt.order_by(DagRun.start_date.is_(None), DagRun.start_date.desc())
+ # A requeued run has no start_date until it starts again, so fall back to
queued_at;
+ # otherwise an older finished run of the same partition is taken as the
latest.
+ latest_attempt = func.coalesce(DagRun.start_date, DagRun.queued_at)
Review Comment:
You are right. A run that goes from QUEUED directly to SUCCESS or FAILED
keeps `start_date` NULL, so the coalesce let it rank above a RUNNING run.
I removed the coalesce. The lookup now sorts queued and running runs first,
then by `start_date` as on `main`. If a partition has any unfinished run, the
lookup returns that run and the backfill records `in flight`. This gives the
same result as the `exists()` check, without a second query, and it applies to
the dry run too.
It also covers your second case: an older queued run behind a newer finished
run. The test now has both cases, and both fail without the change.
I also fixed the comment above `create_dagrun` and the sentence in the
backfill docs.
---
Drafted-by: Claude Code (Fable 5.2); reviewed by `shahar1` 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]