jason810496 commented on code in PR #44121:
URL: https://github.com/apache/airflow/pull/44121#discussion_r1851543242


##########
airflow/api_fastapi/core_api/routes/public/pools.py:
##########
@@ -165,15 +167,51 @@ def patch_pool(
 @pools_router.post(
     "/",
     status_code=status.HTTP_201_CREATED,
-    responses=create_openapi_http_exception_doc([status.HTTP_401_UNAUTHORIZED, 
status.HTTP_403_FORBIDDEN]),
+    responses=create_openapi_http_exception_doc([status.HTTP_409_CONFLICT]),
 )
 def post_pool(
-    post_body: PoolPostBody,
+    body: PoolPostBody,
     session: Annotated[Session, Depends(get_session)],
 ) -> PoolResponse:
     """Create a Pool."""
-    pool = Pool(**post_body.model_dump())
+    pool = Pool(**body.model_dump())
 
     session.add(pool)
+    try:
+        session.commit()
+    except IntegrityError:
+        session.rollback()
+        raise HTTPException(status.HTTP_409_CONFLICT, f"Pool with name: 
`{body.pool}` already exists")
 
     return PoolResponse.model_validate(pool, from_attributes=True)
+
+
+@pools_router.post(
+    "/bulk",
+    status_code=status.HTTP_201_CREATED,
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_409_CONFLICT,
+        ]
+    ),
+)
+def post_pools(
+    body: PoolPostBulkBody,
+    session: Annotated[Session, Depends(get_session)],
+) -> PoolCollectionResponse:
+    """Create multiple pools."""
+    pools = [Pool(**body.model_dump()) for body in body.pools]
+    session.add_all(pools)
+    try:
+        session.commit()
+    except IntegrityError as e:
+        session.rollback()
+        raise HTTPException(
+            status.HTTP_409_CONFLICT,
+            detail=f"One or more pools already exists. Error: {e}",
+        )

Review Comment:
   Hi @pierrejeambrun,  
   I have adopted the global error handler for unique constraint errors. This 
approach can be extended in the future to handle other database constraint 
errors, such as Not Null, Foreign Key, etc.  WDYT?
   



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