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

vincbeck 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 22dfa4e5ba2 Reject pool passed to expand() instead of silently 
ignoring it (#77279)
22dfa4e5ba2 is described below

commit 22dfa4e5ba25549c0c04245ccd64b874012b713d
Author: Ramit Kataria <[email protected]>
AuthorDate: Mon Nov 23 09:54:33 2026 -0700

    Reject pool passed to expand() instead of silently ignoring it (#77279)
    
    A mapped task's pool is the same for all of its map indexes: the
    scheduler reads it from the arguments given to partial() and never sees
    values passed to expand(). Since the Task SDK port (#43076), partial()
    has not recorded a pool when none was given, so expand(pool=[...])
    parsed and every mapped task instance ran in default_pool, while the
    operator built on the worker reported the requested pool. expand_kwargs()
    with a pool key behaved the same way, and a pool of None
    (partial(pool=None), or @task(pool=None) on a mapped task) left the
    mapped task's pool as None.
    
    queue, pool_slots and priority_weight already fail with "unmappable or
    already specified argument". pool now fails the same way: at parse time
    for expand(), and when the task instance starts for expand_kwargs().
---
 task-sdk/src/airflow/sdk/bases/decorator.py        |  3 +++
 task-sdk/src/airflow/sdk/bases/operator.py         |  4 ++++
 .../task_sdk/definitions/test_mappedoperator.py    | 27 ++++++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/task-sdk/src/airflow/sdk/bases/decorator.py 
b/task-sdk/src/airflow/sdk/bases/decorator.py
index 896bedb3abc..2496f77c8ad 100644
--- a/task-sdk/src/airflow/sdk/bases/decorator.py
+++ b/task-sdk/src/airflow/sdk/bases/decorator.py
@@ -31,6 +31,7 @@ import typing_extensions
 from airflow.sdk import TriggerRule, timezone
 from airflow.sdk.bases.operator import (
     BASEOPERATOR_ARGS_EXPECTED_TYPES,
+    DEFAULT_POOL_NAME,
     BaseOperator,
     coerce_resources,
     coerce_timedelta,
@@ -683,6 +684,8 @@ class _TaskDecorator(ExpandableFactory, Generic[FParams, 
FReturn, OperatorSubcla
             partial_kwargs["depends_on_past"] = True
         start_date = timezone.convert_to_utc(partial_kwargs.pop("start_date", 
None))
         end_date = timezone.convert_to_utc(partial_kwargs.pop("end_date", 
None))
+        if partial_kwargs.get("pool") is None:
+            partial_kwargs["pool"] = DEFAULT_POOL_NAME
         if "pool_slots" in partial_kwargs:
             if partial_kwargs["pool_slots"] < 1:
                 dag_str = ""
diff --git a/task-sdk/src/airflow/sdk/bases/operator.py 
b/task-sdk/src/airflow/sdk/bases/operator.py
index 28aeb0959e7..1729e19aeb1 100644
--- a/task-sdk/src/airflow/sdk/bases/operator.py
+++ b/task-sdk/src/airflow/sdk/bases/operator.py
@@ -403,6 +403,10 @@ else:
             partial_kwargs["start_date"] = timezone.convert_to_utc(start_date)
         if end_date := partial_kwargs.get("end_date", None):
             partial_kwargs["end_date"] = timezone.convert_to_utc(end_date)
+        # The scheduler reads a mapped task's pool only from partial_kwargs, 
and the key being
+        # present is what makes expand(pool=...) fail as "unmappable".
+        if partial_kwargs.get("pool") is None:
+            partial_kwargs["pool"] = DEFAULT_POOL_NAME
         if partial_kwargs["pool_slots"] < 1:
             dag_str = ""
             if dag:
diff --git a/task-sdk/tests/task_sdk/definitions/test_mappedoperator.py 
b/task-sdk/tests/task_sdk/definitions/test_mappedoperator.py
index e66183da0bd..d852eb55065 100644
--- a/task-sdk/tests/task_sdk/definitions/test_mappedoperator.py
+++ b/task-sdk/tests/task_sdk/definitions/test_mappedoperator.py
@@ -230,6 +230,33 @@ def test_partial_on_invalid_pool_slots_raises() -> None:
         MockOperator.partial(task_id="pool_slots_test", pool="test", 
pool_slots="a").expand(arg1=[1, 2, 3])
 
 
+def test_expand_rejects_pool() -> None:
+    with pytest.raises(TypeError, match="unmappable or already specified 
argument: pool"):
+        MockOperator.partial(task_id="a").expand(pool=["p1", "p2"])
+
+
+def test_expand_kwargs_rejects_pool_on_unmap() -> None:
+    mapped = MockOperator.partial(task_id="a").expand_kwargs([{"pool": "p1"}])
+    with pytest.raises(TypeError, match="unmappable or already specified 
argument: pool"):
+        mapped.unmap({"pool": "p1"})
+
+
+def test_partial_pool_none_uses_default_pool() -> None:
+    mapped = MockOperator.partial(task_id="a", pool=None).expand(arg1=[1])
+    assert mapped.pool == "default_pool"
+
+
+def test_task_decorator_pool_none_uses_default_pool() -> None:
+    with DAG("test", schedule=None) as dag:
+
+        @dag.task
+        def show(number): ...
+
+        show.override(pool=None).expand(number=[1])
+
+    assert dag.get_task("show").pool == "default_pool"
+
+
 def test_mapped_task_applies_default_args_classic():
     with DAG(
         dag_id="test",

Reply via email to