pierrejeambrun commented on code in PR #44121:
URL: https://github.com/apache/airflow/pull/44121#discussion_r1846103752
##########
airflow/api_fastapi/core_api/routes/public/pools.py:
##########
@@ -167,15 +168,57 @@ 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_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN,
status.HTTP_409_CONFLICT]
+ ),
)
def post_pool(
post_body: PoolPostBody,
session: Annotated[Session, Depends(get_session)],
) -> PoolResponse:
"""Create a Pool."""
+ pool = session.scalar(select(Pool).where(Pool.pool == post_body.pool))
+ if pool is not None:
+ raise HTTPException(status.HTTP_409_CONFLICT, f"Pool with name:
`{post_body.pool}` already exists")
Review Comment:
Database will handle this for us. We do not need an extra query and checking
in the application code. (Just catch the duplicate entry exception from the DB)
##########
airflow/api_fastapi/core_api/datamodels/pools.py:
##########
@@ -72,6 +72,25 @@ class PoolPatchBody(BaseModel):
class PoolPostBody(BasePool):
"""Pool serializer for post bodies."""
- pool: str = Field(alias="name")
+ pool: str = Field(alias="name", max_length=256)
description: str | None = None
include_deferred: bool = False
+
+
+class PoolPostBulkBody(BaseModel):
+ """Pools serializer for post bodies."""
+
+ pools: list[PoolPostBody]
+
+ @field_validator("pools", mode="after")
+ def validate_pools(cls, v: list[PoolPostBody]) -> list[PoolPostBody]:
+ pool_set = set()
+ duplicates = []
+ for pool in v:
+ if pool.pool in pool_set:
+ duplicates.append(pool.pool)
+ else:
+ pool_set.add(pool.pool)
+ if duplicates:
+ raise ValueError(f"Pool name should be unique, found duplicates:
{duplicates}")
+ return v
Review Comment:
Database will handle this for us. We do not need an extra query and checking
in the application code. (Just catch the duplicate entry exception from the DB)
--
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]