o-nikolas commented on code in PR #73154:
URL: https://github.com/apache/airflow/pull/73154#discussion_r4675764852
##########
airflow-core/src/airflow/dag_processing/bundles/manager.py:
##########
@@ -343,15 +343,27 @@ def _extract_and_sign_template(bundle_name: str) ->
tuple[str | None, dict]:
return new_template_, new_params_
stored = {b.name: b for b in
session.scalars(select(DagBundleModel)).all()}
- bundle_to_team = {
- bundle.name: bundle.teams[0].name if len(bundle.teams) == 1 else
None
- for bundle in stored.values()
- }
+ # Not gated on multi_team: this is what removes ownership left over
from an earlier
+ # multi-team setup, which readers such as ``requires_access_dag``
still enforce.
+ bundle_to_team = DagBundleModel.get_team_names(stored.keys(),
session=session)
+
+ teams_by_name: dict[str, Team] = {}
+ if conf.getboolean("core", "multi_team") and (
+ configured_team_names := {
+ config.team_name for config in self._bundle_config.values() if
config.team_name
+ }
+ ):
+ # ``team.name`` compares case-insensitively on MySQL, so ``IN``
can return a row whose
+ # name differs in case from the config value; casefolded keys
still find it.
+ teams_by_name = {
+ team.name.casefold(): team
+ for team in
session.scalars(select(Team).where(Team.name.in_(configured_team_names)))
+ }
for name, config in self._bundle_config.items():
team: Team | None = None
if config.team_name:
- team = session.scalars(select(Team).where(Team.name ==
config.team_name)).one_or_none()
+ team = teams_by_name.get(config.team_name.casefold())
Review Comment:
+1 to normalizing once at config load. Stored names are always lower case
(`TEAM_NAME_PATTERN`, migration 0131), so lower-casing `team_name` when
`_bundle_config` is built would make the `IN` match the same on every backend.
Right now on Postgres a `Team-A` config only resolves if another bundle happens
to name `team-a`.
It would also fix L392, which compares the stored `team-a` with the raw
`Team-A`, so a mixed-case config reassigns the team and logs "Changing
ownership of team 'team-a' from Dag bundle 'x' to 'team-a'" on every sync. That
already happens on main with MySQL; if you'd rather keep the casefold keys,
comparing with `team.name` on L392 fixes it too.
--
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]