uranusjr commented on code in PR #60216:
URL: https://github.com/apache/airflow/pull/60216#discussion_r2670918913
##########
airflow-core/src/airflow/models/backfill.py:
##########
@@ -503,18 +503,25 @@ def _create_backfill(
if no_schedule:
raise DagNoScheduleException(f"{dag_id} has no schedule")
- num_active = session.scalar(
- select(func.count()).where(
+ # Check for overlapping date ranges with active backfills
+ # Two date ranges overlap if: new_from_date <= existing_to_date
+ # AND new_to_date >= existing_from_date
+ overlapping_backfills = session.scalars(
+ select(Backfill).where(
Backfill.dag_id == dag_id,
Backfill.completed_at.is_(None),
+ Backfill.from_date <= to_date,
+ Backfill.to_date >= from_date,
)
- )
- if num_active is None:
- raise UnknownActiveBackfills(dag_id)
- if num_active > 0:
+ ).all()
+
+ if overlapping_backfills:
+ active_ranges = [
+ f"{bf.from_date.isoformat()} to {bf.to_date.isoformat()}" for
bf in overlapping_backfills
+ ]
raise AlreadyRunningBackfill(
- f"Another backfill is running for dag {dag_id}. "
- f"There can be only one running backfill per dag."
+ f"Another backfill is running for DAG {dag_id} with an
overlapping date range. "
Review Comment:
```suggestion
f"Another backfill is running for Dag {dag_id} with an
overlapping date range. "
```
--
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]