You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by pi...@apache.org on 2025/02/25 09:36:39 UTC

(airflow) branch main updated: Pool name shouldn't be updated via pool PATCH API call (#46986)

This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 99c9e48aed6 Pool name shouldn't be updated via pool PATCH API call (#46986)
99c9e48aed6 is described below

commit 99c9e48aed606a4c454a2e1045426cd528bffd77
Author: Shubham Raj <48...@users.noreply.github.com>
AuthorDate: Tue Feb 25 15:06:32 2025 +0530

    Pool name shouldn't be updated via pool PATCH API call (#46986)
    
    * Pool name shouldn't be updated
    
    * Add tests and no name can go with update_mask
---
 .../api_fastapi/core_api/routes/public/pools.py    |  6 ++-
 .../core_api/routes/public/test_pools.py           | 50 +++++++---------------
 2 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/airflow/api_fastapi/core_api/routes/public/pools.py b/airflow/api_fastapi/core_api/routes/public/pools.py
index 6a47a635c7d..67079e5542a 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 c195d8f4221..1121c190c7a 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,