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

o-nikolas 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 5f918917879 Add team name to task CTX (#65617)
5f918917879 is described below

commit 5f9189178791684135ced0d49ab666b6df67aa83
Author: Niko Oliveira <[email protected]>
AuthorDate: Thu Apr 23 13:22:36 2026 -0700

    Add team name to task CTX (#65617)
    
    To be able to tell the team we're executing a task for on the worker
    (for logging, metrics, etc) we need to include the team name as part of
    the context.
---
 .../execution_api/datamodels/taskinstance.py       |  1 +
 .../execution_api/routes/task_instances.py         |  4 +
 .../airflow/api_fastapi/execution_api/security.py  | 29 ++++++--
 .../api_fastapi/execution_api/versions/__init__.py |  5 ++
 .../execution_api/versions/v2026_04_17.py          | 36 +++++++++
 .../execution_api/versions/head/test_dag_runs.py   |  1 +
 .../versions/head/test_task_instances.py           | 58 +++++++++++++++
 .../execution_api/versions/v2026_04_17/__init__.py | 16 ++++
 .../versions/v2026_04_17/test_task_instances.py    | 86 ++++++++++++++++++++++
 .../hive/tests/unit/apache/hive/hooks/test_hive.py |  3 +-
 .../tests/unit/apache/hive/operators/test_hive.py  |  5 ++
 .../src/airflow/sdk/api/datamodels/_generated.py   |  3 +-
 task-sdk/src/airflow/sdk/execution_time/context.py |  5 ++
 .../tests/task_sdk/execution_time/test_context.py  | 14 ++++
 .../task_sdk/execution_time/test_supervisor.py     |  2 +
 15 files changed, 261 insertions(+), 7 deletions(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py 
b/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py
index 395f8281d69..02b82930946 100644
--- 
a/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py
+++ 
b/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py
@@ -306,6 +306,7 @@ class DagRun(StrictBaseModel):
     consumed_asset_events: list[AssetEventDagRunReference]
     partition_key: str | None
     note: str | None = None
+    team_name: str | None = None
 
     @model_validator(mode="before")
     @classmethod
diff --git 
a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py 
b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
index 8f447cab144..51ac334a9e7 100644
--- 
a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
+++ 
b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
@@ -273,6 +273,10 @@ def ti_run(
             or 0
         )
 
+        from airflow.api_fastapi.execution_api.security import 
get_team_name_for_ti
+
+        dr.team_name = get_team_name_for_ti(task_instance_id, session)
+
         context = TIRunContext(
             dag_run=dr,
             task_reschedule_count=task_reschedule_count,
diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/security.py 
b/airflow-core/src/airflow/api_fastapi/execution_api/security.py
index 1100674b727..df3b7993a08 100644
--- a/airflow-core/src/airflow/api_fastapi/execution_api/security.py
+++ b/airflow-core/src/airflow/api_fastapi/execution_api/security.py
@@ -233,18 +233,37 @@ async def get_team_name_dep(token=CurrentTIToken) -> str 
| None:
     if not conf.getboolean("core", "multi_team"):
         return None
 
+    from airflow.utils.session import create_session_async
+
+    async with create_session_async() as session:
+        return await session.scalar(_team_name_for_ti_stmt(token.id))
+
+
+def get_team_name_for_ti(ti_id, session) -> str | None:
+    """
+    Return the team name associated to the task (if any), using a sync session.
+
+    Sync counterpart to :func:`get_team_name_dep` for callers that already 
hold a
+    SQLAlchemy session (e.g., the ``ti_run`` endpoint). No-op when multi-team 
is disabled.
+    """
+    from airflow.configuration import conf
+
+    if not conf.getboolean("core", "multi_team"):
+        return None
+    return session.scalar(_team_name_for_ti_stmt(ti_id))
+
+
+def _team_name_for_ti_stmt(ti_id):
+    """Build the select statement resolving ``TaskInstance.id -> 
Team.name``."""
     from airflow.models import DagModel, TaskInstance
     from airflow.models.dagbundle import DagBundleModel
     from airflow.models.team import Team
-    from airflow.utils.session import create_session_async
 
-    stmt = (
+    return (
         select(Team.name)
         .select_from(TaskInstance)
         .join(DagModel, DagModel.dag_id == TaskInstance.dag_id)
         .join(DagBundleModel, DagBundleModel.name == DagModel.bundle_name)
         .join(DagBundleModel.teams)
-        .where(TaskInstance.id == token.id)
+        .where(TaskInstance.id == ti_id)
     )
-    async with create_session_async() as session:
-        return await session.scalar(stmt)
diff --git 
a/airflow-core/src/airflow/api_fastapi/execution_api/versions/__init__.py 
b/airflow-core/src/airflow/api_fastapi/execution_api/versions/__init__.py
index 9276e537b5e..6863c64efe5 100644
--- a/airflow-core/src/airflow/api_fastapi/execution_api/versions/__init__.py
+++ b/airflow-core/src/airflow/api_fastapi/execution_api/versions/__init__.py
@@ -39,9 +39,14 @@ from airflow.api_fastapi.execution_api.versions.v2026_04_06 
import (
     MovePreviousRunEndpoint,
     RemoveUpstreamMapIndexesField,
 )
+from airflow.api_fastapi.execution_api.versions.v2026_04_17 import 
AddTeamNameField
 
 bundle = VersionBundle(
     HeadVersion(),
+    Version(
+        "2026-04-17",
+        AddTeamNameField,
+    ),
     Version(
         "2026-04-06",
         AddPartitionKeyField,
diff --git 
a/airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_04_17.py 
b/airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_04_17.py
new file mode 100644
index 00000000000..e7cd9d331a5
--- /dev/null
+++ b/airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_04_17.py
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from cadwyn import ResponseInfo, VersionChange, 
convert_response_to_previous_version_for, schema
+
+from airflow.api_fastapi.execution_api.datamodels.taskinstance import DagRun, 
TIRunContext
+
+
+class AddTeamNameField(VersionChange):
+    """Add the ``team_name`` field to DagRun model."""
+
+    description = __doc__
+
+    instructions_to_migrate_to_previous_version = 
(schema(DagRun).field("team_name").didnt_exist,)
+
+    @convert_response_to_previous_version_for(TIRunContext)  # type: 
ignore[arg-type]
+    def remove_team_name_field(response: ResponseInfo) -> None:  # type: 
ignore[misc]
+        """Remove the ``team_name`` field from dag_run for older API 
versions."""
+        if "dag_run" in response.body and isinstance(response.body["dag_run"], 
dict):
+            response.body["dag_run"].pop("team_name", None)
diff --git 
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_dag_runs.py
 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_dag_runs.py
index 8b1fa606694..b84b993f1d6 100644
--- 
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_dag_runs.py
+++ 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_dag_runs.py
@@ -328,6 +328,7 @@ class TestDagRunDetail:
             "state": "success",
             "triggering_user_name": None,
             "note": None,
+            "team_name": None,
         }
 
     def test_dag_run_not_found(self, client):
diff --git 
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
index f00a9b997d1..e73d4aabf84 100644
--- 
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
+++ 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
@@ -42,6 +42,7 @@ from airflow.api_fastapi.execution_api.routes.task_instances 
import _emit_task_s
 from airflow.exceptions import AirflowSkipException
 from airflow.models import RenderedTaskInstanceFields, TaskReschedule, Trigger
 from airflow.models.asset import AssetActive, AssetAliasModel, AssetEvent, 
AssetModel
+from airflow.models.dag import DagModel
 from airflow.models.log import Log
 from airflow.models.taskinstance import TaskInstance
 from airflow.models.taskinstancehistory import TaskInstanceHistory
@@ -232,6 +233,7 @@ class TestTIRunState:
                 "consumed_asset_events": [],
                 "partition_key": None,
                 "note": None,
+                "team_name": None,
             },
             "task_reschedule_count": 0,
             "max_tries": max_tries,
@@ -885,6 +887,62 @@ class TestTIRunState:
         assert dag_run["run_id"] == "test"
         assert dag_run["state"] == "running"
 
+    @pytest.mark.parametrize(
+        ("multi_team_enabled", "expect_team"),
+        [
+            pytest.param("False", False, id="multi-team-disabled"),
+            pytest.param("True", True, id="multi-team-enabled"),
+        ],
+    )
+    def test_ti_run_populates_team_name(
+        self,
+        client,
+        session,
+        dag_maker,
+        time_machine,
+        multi_team_enabled,
+        expect_team,
+    ):
+        """``team_name`` is resolved from the DAG's bundle when multi-team is 
enabled."""
+        from airflow.models.dagbundle import DagBundleModel
+        from airflow.models.team import Team
+
+        instant = timezone.parse("2024-09-30T12:00:00Z")
+        time_machine.move_to(instant, tick=False)
+
+        dag_id = str(uuid4())
+        with dag_maker(dag_id=dag_id, session=session):
+            EmptyOperator(task_id="task")
+        dr = dag_maker.create_dagrun(
+            run_id="test", logical_date=instant, state=DagRunState.RUNNING, 
start_date=instant
+        )
+        ti = dr.get_task_instance(task_id="task")
+        ti.set_state(State.QUEUED)
+
+        bundle_name = f"bundle-{dag_id}"
+        team_name = f"team-{dag_id[:8]}"
+        bundle = DagBundleModel(name=bundle_name)
+        bundle.teams.append(Team(name=team_name))
+        session.add(bundle)
+        session.flush()
+        session.execute(update(DagModel).where(DagModel.dag_id == 
dag_id).values(bundle_name=bundle_name))
+        session.commit()
+
+        with conf_vars({("core", "multi_team"): multi_team_enabled}):
+            response = client.patch(
+                f"/execution/task-instances/{ti.id}/run",
+                json={
+                    "state": "running",
+                    "hostname": "h",
+                    "unixname": "u",
+                    "pid": 1,
+                    "start_date": "2024-09-30T12:00:00Z",
+                },
+            )
+
+        assert response.status_code == 200
+        assert response.json()["dag_run"]["team_name"] == (team_name if 
expect_team else None)
+
     def test_ti_run_creates_audit_log(self, client, session, 
create_task_instance, time_machine):
         """Test that transitioning to RUNNING creates an audit log record."""
         instant_str = "2024-09-30T12:00:00Z"
diff --git 
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_04_17/__init__.py
 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_04_17/__init__.py
new file mode 100644
index 00000000000..13a83393a91
--- /dev/null
+++ 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_04_17/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git 
a/airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_04_17/test_task_instances.py
 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_04_17/test_task_instances.py
new file mode 100644
index 00000000000..71775cb5059
--- /dev/null
+++ 
b/airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_04_17/test_task_instances.py
@@ -0,0 +1,86 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import pytest
+
+from airflow._shared.timezones import timezone
+from airflow.utils.state import DagRunState, State
+
+from tests_common.test_utils.config import conf_vars
+from tests_common.test_utils.db import clear_db_runs
+
+pytestmark = pytest.mark.db_test
+
+TIMESTAMP_STR = "2024-09-30T12:00:00Z"
+TIMESTAMP = timezone.parse(TIMESTAMP_STR)
+
+RUN_PATCH_BODY = {
+    "state": "running",
+    "hostname": "h",
+    "unixname": "u",
+    "pid": 1,
+    "start_date": TIMESTAMP_STR,
+}
+
+
[email protected]
+def old_ver_client(client):
+    """Execution API version immediately before ``team_name`` was added."""
+    client.headers["Airflow-API-Version"] = "2026-04-06"
+    return client
+
+
+class TestTeamNameFieldBackwardCompat:
+    @pytest.fixture(autouse=True)
+    def _freeze_time(self, time_machine):
+        time_machine.move_to(TIMESTAMP_STR, tick=False)
+
+    def setup_method(self):
+        clear_db_runs()
+
+    def teardown_method(self):
+        clear_db_runs()
+
+    def test_old_version_strips_team_name_even_when_set(self, old_ver_client, 
session, create_task_instance):
+        ti = create_task_instance(
+            task_id="test_team_name_downgrade",
+            state=State.QUEUED,
+            dagrun_state=DagRunState.RUNNING,
+            session=session,
+            start_date=TIMESTAMP,
+        )
+        session.commit()
+        with conf_vars({("core", "multi_team"): "False"}):
+            response = 
old_ver_client.patch(f"/execution/task-instances/{ti.id}/run", 
json=RUN_PATCH_BODY)
+        assert response.status_code == 200
+        assert "team_name" not in response.json()["dag_run"]
+
+    def test_head_version_includes_team_name_field(self, client, session, 
create_task_instance):
+        ti = create_task_instance(
+            task_id="test_team_name_head",
+            state=State.QUEUED,
+            dagrun_state=DagRunState.RUNNING,
+            session=session,
+            start_date=TIMESTAMP,
+        )
+        session.commit()
+        with conf_vars({("core", "multi_team"): "False"}):
+            response = client.patch(f"/execution/task-instances/{ti.id}/run", 
json=RUN_PATCH_BODY)
+        assert response.status_code == 200
+        assert response.json()["dag_run"]["team_name"] is None
diff --git a/providers/apache/hive/tests/unit/apache/hive/hooks/test_hive.py 
b/providers/apache/hive/tests/unit/apache/hive/hooks/test_hive.py
index 1508b203012..79ce39cd40a 100644
--- a/providers/apache/hive/tests/unit/apache/hive/hooks/test_hive.py
+++ b/providers/apache/hive/tests/unit/apache/hive/hooks/test_hive.py
@@ -35,7 +35,7 @@ from airflow.secrets.environment_variables import 
CONN_ENV_PREFIX
 from airflow.utils import timezone
 
 from tests_common.test_utils.asserts import assert_equal_ignore_multiple_spaces
-from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS, 
AIRFLOW_V_3_3_PLUS
 from unit.apache.hive import (
     BaseMockConnectionCursor,
     InvalidHiveCliHook,
@@ -99,6 +99,7 @@ class TestHiveCliHook:
             "airflow.ctx.dag_owner=airflow",
             "-hiveconf",
             "[email protected]",
+            *(["-hiveconf", "airflow.ctx.team_name="] if AIRFLOW_V_3_3_PLUS 
else []),
             "-hiveconf",
             "mapreduce.job.queuename=airflow",
             "-hiveconf",
diff --git 
a/providers/apache/hive/tests/unit/apache/hive/operators/test_hive.py 
b/providers/apache/hive/tests/unit/apache/hive/operators/test_hive.py
index b2f5c6193dd..7fea8808972 100644
--- a/providers/apache/hive/tests/unit/apache/hive/operators/test_hive.py
+++ b/providers/apache/hive/tests/unit/apache/hive/operators/test_hive.py
@@ -27,6 +27,7 @@ from airflow.providers.apache.hive.operators.hive import 
HiveOperator
 from airflow.providers.common.compat.sdk import conf
 from airflow.utils import timezone
 
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_3_PLUS
 from unit.apache.hive import DEFAULT_DATE, MockSubProcess, TestHiveEnvironment
 
 
@@ -125,6 +126,7 @@ class TestHivePresto(TestHiveEnvironment):
             "airflow.ctx.dag_owner=airflow",
             "-hiveconf",
             "airflow.ctx.dag_email=",
+            *(["-hiveconf", "airflow.ctx.team_name="] if AIRFLOW_V_3_3_PLUS 
else []),
             "-hiveconf",
             "mapreduce.job.queuename=airflow",
             "-hiveconf",
@@ -169,6 +171,7 @@ class TestHivePresto(TestHiveEnvironment):
             "airflow.ctx.dag_owner=airflow",
             "-hiveconf",
             "airflow.ctx.dag_email=",
+            *(["-hiveconf", "airflow.ctx.team_name="] if AIRFLOW_V_3_3_PLUS 
else []),
             "-hiveconf",
             "mapreduce.job.queuename=default",
             "-hiveconf",
@@ -227,6 +230,7 @@ class TestHivePresto(TestHiveEnvironment):
             "airflow.ctx.dag_owner=",
             "-hiveconf",
             "airflow.ctx.dag_email=",
+            *(["-hiveconf", "airflow.ctx.team_name="] if AIRFLOW_V_3_3_PLUS 
else []),
             "-hiveconf",
             "mapreduce.job.queuename=airflow",
             "-hiveconf",
@@ -268,6 +272,7 @@ class TestHivePresto(TestHiveEnvironment):
             "airflow.ctx.dag_owner=airflow",
             "-hiveconf",
             "airflow.ctx.dag_email=",
+            *(["-hiveconf", "airflow.ctx.team_name="] if AIRFLOW_V_3_3_PLUS 
else []),
             "-hiveconf",
             "mapreduce.job.queuename=airflow",
             "-hiveconf",
diff --git a/task-sdk/src/airflow/sdk/api/datamodels/_generated.py 
b/task-sdk/src/airflow/sdk/api/datamodels/_generated.py
index 2789af8aacc..138fe8a9fd8 100644
--- a/task-sdk/src/airflow/sdk/api/datamodels/_generated.py
+++ b/task-sdk/src/airflow/sdk/api/datamodels/_generated.py
@@ -27,7 +27,7 @@ from uuid import UUID
 
 from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, JsonValue, 
RootModel
 
-API_VERSION: Final[str] = "2026-04-06"
+API_VERSION: Final[str] = "2026-04-17"
 
 
 class AssetAliasReferenceAssetEventDagRun(BaseModel):
@@ -647,6 +647,7 @@ class DagRun(BaseModel):
     consumed_asset_events: Annotated[list[AssetEventDagRunReference], 
Field(title="Consumed Asset Events")]
     partition_key: Annotated[str | None, Field(title="Partition Key")] = None
     note: Annotated[str | None, Field(title="Note")] = None
+    team_name: Annotated[str | None, Field(title="Team Name")] = None
 
 
 class TIRunContext(BaseModel):
diff --git a/task-sdk/src/airflow/sdk/execution_time/context.py 
b/task-sdk/src/airflow/sdk/execution_time/context.py
index db5a75e10c1..0554e41c2e6 100644
--- a/task-sdk/src/airflow/sdk/execution_time/context.py
+++ b/task-sdk/src/airflow/sdk/execution_time/context.py
@@ -100,6 +100,10 @@ AIRFLOW_VAR_NAME_FORMAT_MAPPING = {
         "default": f"{DEFAULT_FORMAT_PREFIX}dag_email",
         "env_var_format": f"{ENV_VAR_FORMAT_PREFIX}DAG_EMAIL",
     },
+    "AIRFLOW_CONTEXT_TEAM_NAME": {
+        "default": f"{DEFAULT_FORMAT_PREFIX}team_name",
+        "env_var_format": f"{ENV_VAR_FORMAT_PREFIX}TEAM_NAME",
+    },
 }
 
 
@@ -868,6 +872,7 @@ def context_to_airflow_vars(context: Mapping[str, Any], 
in_env_var_format: bool
         (dag_run, "logical_date", "AIRFLOW_CONTEXT_LOGICAL_DATE"),
         (task_instance, "try_number", "AIRFLOW_CONTEXT_TRY_NUMBER"),
         (dag_run, "run_id", "AIRFLOW_CONTEXT_DAG_RUN_ID"),
+        (dag_run, "team_name", "AIRFLOW_CONTEXT_TEAM_NAME"),
     ]
 
     context_params = settings.get_airflow_context_vars(context)
diff --git a/task-sdk/tests/task_sdk/execution_time/test_context.py 
b/task-sdk/tests/task_sdk/execution_time/test_context.py
index a2c3310822b..1b0be13ab3a 100644
--- a/task-sdk/tests/task_sdk/execution_time/test_context.py
+++ b/task-sdk/tests/task_sdk/execution_time/test_context.py
@@ -159,6 +159,20 @@ class TestAirflowContextHelpers:
             "AIRFLOW_CTX_DAG_EMAIL": "[email protected]",
         }
 
+    def test_context_to_airflow_vars_team_name(self, create_runtime_ti):
+        """``team_name`` on dag_run surfaces as AIRFLOW_CTX_TEAM_NAME when 
set; omitted when None."""
+        task = BaseOperator(task_id="task")
+        rti = create_runtime_ti(task=task)
+        context = rti.get_template_context()
+
+        # Default (team_name is None) -> key not present
+        assert "AIRFLOW_CTX_TEAM_NAME" not in context_to_airflow_vars(context, 
in_env_var_format=True)
+
+        context["dag_run"].team_name = "team-a"
+        env_vars = context_to_airflow_vars(context, in_env_var_format=True)
+        assert env_vars["AIRFLOW_CTX_TEAM_NAME"] == "team-a"
+        assert context_to_airflow_vars(context)["airflow.ctx.team_name"] == 
"team-a"
+
     def test_context_to_airflow_vars_from_policy(self):
         with mock.patch("airflow.settings.get_airflow_context_vars") as 
mock_method:
             airflow_cluster = "cluster-a"
diff --git a/task-sdk/tests/task_sdk/execution_time/test_supervisor.py 
b/task-sdk/tests/task_sdk/execution_time/test_supervisor.py
index a0bf5300f0c..334dfee4e10 100644
--- a/task-sdk/tests/task_sdk/execution_time/test_supervisor.py
+++ b/task-sdk/tests/task_sdk/execution_time/test_supervisor.py
@@ -2213,6 +2213,7 @@ REQUEST_TEST_CASES = [
             "triggering_user_name": None,
             "type": "DagRunResult",
             "note": None,
+            "team_name": None,
         },
         client_mock=ClientMock(
             method_path="dag_runs.get_detail",
@@ -2264,6 +2265,7 @@ REQUEST_TEST_CASES = [
                 "conf": None,
                 "triggering_user_name": None,
                 "note": None,
+                "team_name": None,
             },
             "type": "PreviousDagRunResult",
         },

Reply via email to