Skip to content

Variable.set rewrites team_name of an existing variable in multi-team mode - intended? #71810

Closed

Description

@taehwoi

Is it intended that Variable.set() rewrites the team_name of an existing row to the caller's team when core.multi_team = True? A value-only update changes ownership.

Repro

Variable.set(key="k", value="v1")                        # team_name = NULL
Variable.set(key="k", value="v2", team_name="team_a")    # team_name = team_a
Variable.get("k")                                        # KeyError
  • The third call fails because MetastoreBackend.get_variable filters on or_(Variable.team_name == team_name, Variable.team_name.is_(None)) (airflow/secrets/metastore.py), so a team-less lookup only matches NULL rows. DAG parsing is such a lookup: airflow/sdk/execution_time/context.py calls secrets_backend.get_variable(key=key) with no team.
  • variable.key is unique=True on its own, so the same key cannot exist for two teams. team_name is not a namespace.
  • Variable.set puts team_name in update_fields and passes it to build_upsert_stmt(..., conflict_cols=["key"], ...), which compiles to ON CONFLICT (key) DO UPDATE SET ..., team_name = :team_name (airflow/utils/sqlalchemy.py).

Seen on 3.3.0, same code in 3.2.1.

Activity

  1. added
    kind:bug
    on Aug 19, 2026
  2. saitejabandaru-in commented on Aug 19, 2026

    @saitejabandaru-in

    Since Variable.set currently behaves like an upsert (ON CONFLICT (key) DO UPDATE) based exclusively on key, it blindly overwrites the existing row matching the key, including its team_name.

    Because key alone is marked as unique=True in the database schema, Airflow does not treat team_name as a namespace partition. The same key cannot exist across different teams.

    This is arguably a design flaw in how the new core.multi_team feature was integrated with Variable.set(). A global/shared variable (where team_name=None) should probably have its ownership preserved upon a value-only update, or at the very least, updating a variable owned by team_a shouldn't silently steal ownership if the updater doesn't explicitly intend to do so.

    To fix this, Variable.set could be updated so that team_name is excluded from the update_fields of build_upsert_stmt during an upsert if team_name is not explicitly passed (or perhaps ownership transfers should be blocked entirely on upserts unless explicitly requested).

    Alternatively, if the intention of multi-team is full logical isolation, the database unique constraint should arguably be (key, team_name) rather than just key, which would allow true multi-tenant namespace isolation for variables (so team_a and team_b can both have a variable named k). But that would be a larger breaking schema change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions