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


##########
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:
   This can be potentially quite expensive. I would suggest keep using the 
`count()` approach. _Maybe_ this can be called if logging is set to DEBUG to 
log a message.



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