pierrejeambrun commented on code in PR #45062:
URL: https://github.com/apache/airflow/pull/45062#discussion_r1897346260


##########
airflow/api_fastapi/core_api/routes/public/backfills.py:
##########
@@ -206,3 +213,55 @@ def create_backfill(
             status_code=status.HTTP_409_CONFLICT,
             detail=f"There is already a running backfill for dag 
{backfill_request.dag_id}",
         )
+
+
+@backfills_router.post(
+    path="/dry_run",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_404_NOT_FOUND,
+            status.HTTP_409_CONFLICT,
+        ]
+    ),
+)
+def create_backfill_dry_run(
+    backfill_request: BackfillPostBody,
+    session: SessionDep,
+) -> BackfillDryRunResponse:
+    from_date = timezone.coerce_datetime(backfill_request.from_date)
+    to_date = timezone.coerce_datetime(backfill_request.to_date)
+    serdag = 
session.scalar(SerializedDagModel.latest_item_select_object(backfill_request.dag_id))
+    if not serdag:
+        raise HTTPException(status_code=404, detail=f"Could not find dag 
{backfill_request.dag_id}")
+
+    info_list = _get_info_list(
+        dag=serdag.dag,
+        from_date=from_date,
+        to_date=to_date,
+        reverse=backfill_request.run_backwards,
+    )
+    backfill_response_item = []
+    for info in info_list:
+        dr = session.scalar(
+            select(DagRun)
+            .where(DagRun.logical_date == info.logical_date)
+            .order_by(nulls_first(desc(DagRun.start_date), session))
+            .limit(1)
+        )

Review Comment:
   I think we should change this pattern to make only one request do the db. 
Maybe something like:
   
   ```python
   dag_runs = ......where(DagRun.logical_date in [info.logical_date for info in 
....])
   ```
   
   Queries to the db are expensive and we should avoid multiplying them.



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