Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool name shouldn't be updated via pool PATCH API call #46986

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 != 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
48 changes: 11 additions & 37 deletions tests/api_fastapi/core_api/routes/public/test_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,83 +143,57 @@ class TestPatchPool(TestPoolsEndpoint):
(
Pool.DEFAULT_POOL_NAME,
{},
{},
{"pool": Pool.DEFAULT_POOL_NAME},
400,
{"detail": "Only slots and included_deferred can be modified on Default Pool"},
),
(
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"},
),
(
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,
{"update_mask": ["slots"]},
{"slots": 150},
{"pool": Pool.DEFAULT_POOL_NAME, "slots": 150},
200,
{
"deferred_slots": 0,
Expand All @@ -238,7 +212,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 +234,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