From 60e99275fdb4e55948a1e0a064d129f03e3e2a81 Mon Sep 17 00:00:00 2001 From: Dominik <29484605+dominik-korsa@users.noreply.github.com> Date: Sun, 28 Dec 2025 18:50:32 +0100 Subject: [PATCH] revert: Revert error handling change in `KeycloakAdmin.get_group_by_path` (#676) This change was introduced in https://github.com/marcospereirampj/python-keycloak/pull/627 Co-authored-by: Richard Nemeth BREAKING CHANGE: changes the behavior of get_group_by_path to raise an exception in case the path is not found, which is now the definitive new behavior --- src/keycloak/keycloak_admin.py | 9 +++++++-- tests/test_keycloak_admin.py | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index 9174f91..6ea4bf6 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -39,7 +39,6 @@ from .exceptions import ( HTTP_CONFLICT, HTTP_CREATED, HTTP_NO_CONTENT, - HTTP_NOT_FOUND, HTTP_OK, KeycloakDeleteError, KeycloakGetError, @@ -1948,6 +1947,8 @@ class KeycloakAdmin: Returns full group details for a group defined by path + Raises an `KeycloakGetError` if the group was not found. + GroupRepresentation https://www.keycloak.org/docs-api/24.0.2/rest-api/#_grouprepresentation @@ -1960,7 +1961,11 @@ class KeycloakAdmin: data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path), ) - return raise_error_from_response(data_raw, KeycloakGetError, [HTTP_OK, HTTP_NOT_FOUND]) + # PR https://github.com/marcospereirampj/python-keycloak/pull/627 + # added `HTTP_NOT_FOUND` to the `expected_codes` argument. + # This change has since been reverted, see: + # https://github.com/marcospereirampj/python-keycloak/issues/675 + return raise_error_from_response(data_raw, KeycloakGetError) def create_group( self, diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index f27de1a..a0ccf8d 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -1013,8 +1013,10 @@ def test_groups(admin: KeycloakAdmin, user: str) -> None: assert res is not None, res assert res["id"] == subgroup_id_1, res - res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test") - assert res["error"] == "Group path does not exist" + # See https://github.com/marcospereirampj/python-keycloak/issues/675 + with pytest.raises(KeycloakGetError) as err: + admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/does-not-exist") + assert err.match('404: b\'{"error":"Group path does not exist".*}\'') res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1") assert res is not None, res