Skip to content

Commit 60e9927

Browse files
revert: Revert error handling change in KeycloakAdmin.get_group_by_path (#676)
This change was introduced in #627 Co-authored-by: Richard Nemeth <ryshoooo@gmail.com> 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
1 parent 3ea146d commit 60e9927

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/keycloak/keycloak_admin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
HTTP_CONFLICT,
4040
HTTP_CREATED,
4141
HTTP_NO_CONTENT,
42-
HTTP_NOT_FOUND,
4342
HTTP_OK,
4443
KeycloakDeleteError,
4544
KeycloakGetError,
@@ -1948,6 +1947,8 @@ def get_group_by_path(self, path: str) -> dict:
19481947
19491948
Returns full group details for a group defined by path
19501949
1950+
Raises an `KeycloakGetError` if the group was not found.
1951+
19511952
GroupRepresentation
19521953
https://www.keycloak.org/docs-api/24.0.2/rest-api/#_grouprepresentation
19531954
@@ -1960,7 +1961,11 @@ def get_group_by_path(self, path: str) -> dict:
19601961
data_raw = self.connection.raw_get(
19611962
urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path),
19621963
)
1963-
return raise_error_from_response(data_raw, KeycloakGetError, [HTTP_OK, HTTP_NOT_FOUND])
1964+
# PR https://github.com/marcospereirampj/python-keycloak/pull/627
1965+
# added `HTTP_NOT_FOUND` to the `expected_codes` argument.
1966+
# This change has since been reverted, see:
1967+
# https://github.com/marcospereirampj/python-keycloak/issues/675
1968+
return raise_error_from_response(data_raw, KeycloakGetError)
19641969

19651970
def create_group(
19661971
self,

tests/test_keycloak_admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,10 @@ def test_groups(admin: KeycloakAdmin, user: str) -> None:
10131013
assert res is not None, res
10141014
assert res["id"] == subgroup_id_1, res
10151015

1016-
res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/test")
1017-
assert res["error"] == "Group path does not exist"
1016+
# See https://github.com/marcospereirampj/python-keycloak/issues/675
1017+
with pytest.raises(KeycloakGetError) as err:
1018+
admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1/does-not-exist")
1019+
assert err.match('404: b\'{"error":"Group path does not exist".*}\'')
10181020

10191021
res = admin.get_group_by_path(path="/main-group/subgroup-2/subsubgroup-1")
10201022
assert res is not None, res

0 commit comments

Comments
 (0)