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


##########
airflow/api_fastapi/core_api/routes/public/backfills.py:
##########
@@ -206,31 +206,20 @@ def create_backfill(
             reprocess_behavior=backfill_request.reprocess_behavior,
         )
         return BackfillResponse.model_validate(backfill_obj)
-    except AlreadyRunningBackfill:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"There is already a running backfill for dag 
{backfill_request.dag_id}",
-        )
-    except DagNoScheduleException:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"{backfill_request.dag_id} has no schedule",
-        )
-
-    except DagNotFound:
-        raise HTTPException(
-            status_code=status.HTTP_404_NOT_FOUND,
-            detail=f"Could not find dag {backfill_request.dag_id}",
-        )
+    except (
+        AlreadyRunningBackfill,
+        InvalidReprocessBehavior,
+        InvalidBackfillDirection,
+        DagNoScheduleException,
+        DagNotFound,
+    ) as e:
+        raise RequestValidationError(str(e))
 
 
 @backfills_router.post(
     path="/dry_run",
     responses=create_openapi_http_exception_doc(
-        [
-            status.HTTP_404_NOT_FOUND,
-            status.HTTP_409_CONFLICT,
-        ]
+        [status.HTTP_404_NOT_FOUND, status.HTTP_409_CONFLICT, 
status.HTTP_422_UNPROCESSABLE_ENTITY]

Review Comment:
   `HTTP_422_UNPROCESSABLE_ENTITY` this is already handled by pydantic 
natively, we don't need to specify it.



##########
airflow/api_fastapi/core_api/routes/public/backfills.py:
##########
@@ -252,13 +241,6 @@ def create_backfill_dry_run(
         backfills = [DryRunBackfillResponse(logical_date=d) for d in 
backfills_dry_run]
 
         return DryRunBackfillCollectionResponse(backfills=backfills, 
total_entries=len(backfills_dry_run))
-    except DagNotFound:
-        raise HTTPException(
-            status_code=status.HTTP_404_NOT_FOUND,
-            detail=f"Could not find dag {body.dag_id}",
-        )
-    except DagNoScheduleException:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"{body.dag_id} has no schedule",
-        )
+
+    except (InvalidReprocessBehavior, InvalidBackfillDirection, 
DagNoScheduleException, DagNotFound) as e:

Review Comment:
   `DagNotFound` keep old handling.



##########
airflow/api_fastapi/core_api/routes/public/backfills.py:
##########
@@ -206,31 +206,20 @@ def create_backfill(
             reprocess_behavior=backfill_request.reprocess_behavior,
         )
         return BackfillResponse.model_validate(backfill_obj)
-    except AlreadyRunningBackfill:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"There is already a running backfill for dag 
{backfill_request.dag_id}",
-        )
-    except DagNoScheduleException:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"{backfill_request.dag_id} has no schedule",
-        )
-
-    except DagNotFound:
-        raise HTTPException(
-            status_code=status.HTTP_404_NOT_FOUND,
-            detail=f"Could not find dag {backfill_request.dag_id}",
-        )
+    except (
+        AlreadyRunningBackfill,

Review Comment:
   DagNotFound is a 404, same we don't want to return a validation error 422 on 
that.



##########
airflow/api_fastapi/core_api/routes/public/backfills.py:
##########
@@ -206,31 +206,20 @@ def create_backfill(
             reprocess_behavior=backfill_request.reprocess_behavior,
         )
         return BackfillResponse.model_validate(backfill_obj)
-    except AlreadyRunningBackfill:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"There is already a running backfill for dag 
{backfill_request.dag_id}",
-        )
-    except DagNoScheduleException:
-        raise HTTPException(
-            status_code=status.HTTP_409_CONFLICT,
-            detail=f"{backfill_request.dag_id} has no schedule",
-        )
-
-    except DagNotFound:
-        raise HTTPException(
-            status_code=status.HTTP_404_NOT_FOUND,
-            detail=f"Could not find dag {backfill_request.dag_id}",
-        )
+    except (
+        AlreadyRunningBackfill,

Review Comment:
   `AlreadyRunningBackfill` needs to remain on it's own because it's a `409` 
conflict. 
   
   `RequestValidationError` will return a 422.



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