diff --git a/airflow/api_fastapi/core_api/routes/public/pools.py b/airflow/api_fastapi/core_api/routes/public/pools.py index 6a47a635c7db0..67079e5542acb 100644 --- a/airflow/api_fastapi/core_api/routes/public/pools.py +++ b/airflow/api_fastapi/core_api/routes/public/pools.py @@ -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): @@ -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( diff --git a/tests/api_fastapi/core_api/routes/public/test_pools.py b/tests/api_fastapi/core_api/routes/public/test_pools.py index c195d8f42215b..1121c190c7ace 100644 --- a/tests/api_fastapi/core_api/routes/public/test_pools.py +++ b/tests/api_fastapi/core_api/routes/public/test_pools.py @@ -150,44 +150,46 @@ 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", @@ -195,26 +197,6 @@ class TestPatchPool(TestPoolsEndpoint): ], }, ), - # 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, @@ -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, @@ -260,7 +242,7 @@ class TestPatchPool(TestPoolsEndpoint): { "slots": 8, "description": "Description Updated", - "name": "pool_1_updated", + "name": POOL1_NAME, "include_deferred": False, }, 200, @@ -268,7 +250,7 @@ class TestPatchPool(TestPoolsEndpoint): "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,