From 351a027ce46c7e1fc44cbaa62cd6407a4d7a0db5 Mon Sep 17 00:00:00 2001 From: Stephen Bracken Date: Wed, 24 Jun 2026 09:16:25 +0100 Subject: [PATCH] Raise a warning instead of an error if extra teams are defined in the auth manager --- .../auth/managers/base_auth_manager.py | 12 ++++++++-- .../auth/managers/test_base_auth_manager.py | 22 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/auth/managers/base_auth_manager.py b/airflow-core/src/airflow/api_fastapi/auth/managers/base_auth_manager.py index 4ba08e5b447e5..d587ec7a68004 100644 --- a/airflow-core/src/airflow/api_fastapi/auth/managers/base_auth_manager.py +++ b/airflow-core/src/airflow/api_fastapi/auth/managers/base_auth_manager.py @@ -127,8 +127,16 @@ def init(self) -> None: db_teams = Team.get_all_team_names() if not db_teams.issuperset(am_teams): - raise ValueError( - f"Teams defined in the auth manager ({am_teams}) are not present in the database ({db_teams})." + warnings.warn( + f"Teams defined in the auth manager are not present in the database ({am_teams.difference(db_teams)}).", + UserWarning, + stacklevel=2, + ) + if not am_teams.issuperset(db_teams): + warnings.warn( + f"Teams defined in the database are not present in the auth manager ({db_teams.difference(am_teams)}).", + UserWarning, + stacklevel=2, ) @abstractmethod diff --git a/airflow-core/tests/unit/api_fastapi/auth/managers/test_base_auth_manager.py b/airflow-core/tests/unit/api_fastapi/auth/managers/test_base_auth_manager.py index 18898bddd2d21..348bce778ec0c 100644 --- a/airflow-core/tests/unit/api_fastapi/auth/managers/test_base_auth_manager.py +++ b/airflow-core/tests/unit/api_fastapi/auth/managers/test_base_auth_manager.py @@ -161,10 +161,11 @@ def test_init_non_multi_team_mode(self, auth_manager): @pytest.mark.parametrize( ("auth_manager_teams", "db_teams", "expected"), [ - ({"teamA", "teamB"}, {"teamA", "teamB"}, True), - ({"teamA", "teamB"}, {"teamA", "teamB", "teamC"}, True), - (set(), set(), True), - ({"teamA", "teamB"}, {"teamA", "teamC"}, False), + pytest.param({"teamA", "teamB"}, {"teamA", "teamB"}, "same", id="same teams"), + pytest.param({"teamA", "teamB"}, {"teamA", "teamB", "teamC"}, "extra_db", id="extra teams db"), + pytest.param(set(), set(), "same", id="no teams"), + pytest.param({"teamA", "teamB"}, {"teamA"}, "extra_auth", id="extra teams auth"), + pytest.param({"teamA", "teamB"}, {"teamA", "teamC"}, "extra_both", id="extra teams both"), ], ) @patch.object(Team, "get_all_team_names") @@ -175,10 +176,19 @@ def test_init_multi_team_mode( mock_get_teams.return_value = auth_manager_teams mock_get_all_team_names.return_value = db_teams - if expected: + if expected == "same": assert auth_manager.init() is None + elif expected == "extra_auth": + with pytest.warns(UserWarning, match="Teams defined in the auth manager"): + auth_manager.init() + elif expected == "extra_db": + with pytest.warns(UserWarning, match="Teams defined in the database"): + auth_manager.init() else: - with pytest.raises(ValueError, match="Teams defined in the auth manager"): + with ( + pytest.warns(UserWarning, match="Teams defined in the database"), + pytest.warns(UserWarning, match="Teams defined in the auth manager"), + ): auth_manager.init() def test_get_cli_commands_return_empty_list(self, auth_manager):