taehwoi opened a new issue, #71810:
URL: https://github.com/apache/airflow/issues/71810
### Question
With `core.multi_team = True`, `Variable.set()` rewrites
`variable.team_name` to the caller's team when the row already exists. A
value-only update therefore changes ownership. Is that intended?
### Repro (postgres, multi_team enabled)
```python
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:
Variable k does not exist
```
The third call is what DAG parsing does:
`airflow/sdk/execution_time/context.py` calls
`secrets_backend.get_variable(key=key)` with no team, and
`MetastoreBackend.get_variable` filters
`or_(Variable.team_name == team_name, Variable.team_name.is_(None))`
(`airflow/secrets/metastore.py`), so only `NULL` rows match.
In practice: a variable read at parse time and written from a team task
becomes invisible to the parser after the first write, and the DAGs built from
it disappear.
### Why it reads as accidental
- `variable.key` is `unique=True` on its own, so the same key cannot exist
for two teams. `team_name` is an ownership/visibility tag, not a namespace.
- Reads treat `team_name IS NULL` as shared, so a value update demotes a
shared variable to a single team.
- `Variable.set` puts `team_name` in `update_fields` and calls
`build_upsert_stmt(..., conflict_cols=["key"], ...)`, which compiles to `ON
CONFLICT (key) DO UPDATE SET ..., team_name = :team_name`
(`airflow/utils/sqlalchemy.py`). Nothing preserves the existing owner.
- `Connection` has the same shape: `conn_id` unique on its own plus a
`team_name` column.
If ownership transfer on write is intended, this is worth a note in the
multi-team docs. If not, dropping `team_name` from the conflict update keeps
value writes ownership-neutral.
Seen on 3.3.0. Same code in 3.2.1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]