dstandish commented on code in PR #60216:
URL: https://github.com/apache/airflow/pull/60216#discussion_r2759491039


##########
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,
             )
-        )

Review Comment:
   Yeah queries like that are expensive typically, but there should _never_ be 
a ton of candidate rows (i.e. with completed_at not null



-- 
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]

Reply via email to