Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion airflow/api_fastapi/core_api/routes/public/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def patch_pool(
update_mask: list[str] | None = Query(None),
) -> PoolResponse:
"""Update a Pool."""
if patch_body.name and patch_body.name != pool_name:
raise HTTPException(
status.HTTP_400_BAD_REQUEST,
"Invalid body, pool name from request body doesn't match uri parameter",
)
# Only slots and include_deferred can be modified in 'default_pool'
if pool_name == Pool.DEFAULT_POOL_NAME:
if update_mask and all(mask.strip() in {"slots", "include_deferred"} for mask in update_mask):
Expand All @@ -143,7 +148,6 @@ def patch_pool(
status.HTTP_400_BAD_REQUEST,
"Only slots and included_deferred can be modified on Default Pool",
)

pool = session.scalar(select(Pool).where(Pool.pool == pool_name).limit(1))
if not pool:
raise HTTPException(
Expand Down
50 changes: 16 additions & 34 deletions tests/api_fastapi/core_api/routes/public/test_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,71 +150,53 @@ class TestPatchPool(TestPoolsEndpoint):
(
Pool.DEFAULT_POOL_NAME,
{"update_mask": ["description"]},
{},
{"pool": Pool.DEFAULT_POOL_NAME},
400,
{"detail": "Only slots and included_deferred can be modified on Default Pool"},
),
(
"unknown_pool",
{},
{},
{"pool": "unknown_pool"},
404,
{"detail": "The Pool with name: `unknown_pool` was not found"},
),
# Pool name can't be updated
(
POOL1_NAME,
{},
{"pool": "pool1_updated"},
400,
{"detail": "Invalid body, pool name from request body doesn't match uri parameter"},
),
(
POOL1_NAME,
{},
{"pool": POOL1_NAME},
422,
{
"detail": [
{
"input": {},
"loc": ["pool"],
"msg": "Field required",
"type": "missing",
},
{
"input": {},
"input": {"pool": POOL1_NAME},
"loc": ["slots"],
"msg": "Field required",
"type": "missing",
},
{
"input": {},
"input": {"pool": POOL1_NAME},
"loc": ["description"],
"msg": "Field required",
"type": "missing",
},
{
"input": {},
"input": {"pool": POOL1_NAME},
"loc": ["include_deferred"],
"msg": "Field required",
"type": "missing",
},
],
},
),
# Success
# Partial body
(
POOL1_NAME,
{"update_mask": ["name"]},
{"slots": 150, "name": "pool_1_updated"},
200,
{
"deferred_slots": 0,
"description": None,
"include_deferred": True,
"name": "pool_1_updated",
"occupied_slots": 0,
"open_slots": 3,
"queued_slots": 0,
"running_slots": 0,
"scheduled_slots": 0,
"slots": 3,
},
),
# Partial body on default_pool
(
Pool.DEFAULT_POOL_NAME,
Expand All @@ -238,7 +220,7 @@ class TestPatchPool(TestPoolsEndpoint):
(
Pool.DEFAULT_POOL_NAME,
{"update_mask": ["slots", "include_deferred"]},
{"slots": 150, "include_deferred": True},
{"pool": Pool.DEFAULT_POOL_NAME, "slots": 150, "include_deferred": True},
200,
{
"deferred_slots": 0,
Expand All @@ -260,15 +242,15 @@ class TestPatchPool(TestPoolsEndpoint):
{
"slots": 8,
"description": "Description Updated",
"name": "pool_1_updated",
"name": POOL1_NAME,
"include_deferred": False,
},
200,
{
"deferred_slots": 0,
"description": "Description Updated",
"include_deferred": False,
"name": "pool_1_updated",
"name": POOL1_NAME,
"occupied_slots": 0,
"open_slots": 8,
"queued_slots": 0,
Expand Down