You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variable.set rewrites team_name of an existing variable in multi-team mode - intended? #71810
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.
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).
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.
Activity
saitejabandaru-in commentedon Aug 19, 2026
Since
Variable.setcurrently behaves like an upsert (ON CONFLICT (key) DO UPDATE) based exclusively onkey, it blindly overwrites the existing row matching thekey, including itsteam_name.Because
keyalone is marked asunique=Truein the database schema, Airflow does not treatteam_nameas a namespace partition. The same key cannot exist across different teams.This is arguably a design flaw in how the new
core.multi_teamfeature was integrated withVariable.set(). A global/shared variable (whereteam_name=None) should probably have its ownership preserved upon a value-only update, or at the very least, updating a variable owned byteam_ashouldn't silently steal ownership if the updater doesn't explicitly intend to do so.To fix this,
Variable.setcould be updated so thatteam_nameis excluded from theupdate_fieldsofbuild_upsert_stmtduring an upsert ifteam_nameis 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 justkey, which would allow true multi-tenant namespace isolation for variables (soteam_aandteam_bcan both have a variable namedk). But that would be a larger breaking schema change.