Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycloak admin get_group_by_path raises exception by not found #617

Closed
gbaru opened this issue Nov 25, 2024 · 1 comment · Fixed by #627
Closed

Keycloak admin get_group_by_path raises exception by not found #617

gbaru opened this issue Nov 25, 2024 · 1 comment · Fixed by #627
Assignees

Comments

@gbaru
Copy link

gbaru commented Nov 25, 2024

if a groups is not existing or cannot be found, get_groups_by_path raises an exception.
I inspected the code for this and I was able to find a turn around introducing the possible return codes as acceptable result:
Module keycloak_admin.py, line 1413:
Instead of:
"return raise_error_from_response(data_raw, KeycloakGetError)"
I replaced with:
"return raise_error_from_response(data_raw, KeycloakGetError, [200, 404] )"

It works, but I would like to know if there are better solutions.

@ryshoooo ryshoooo self-assigned this Dec 14, 2024
@Galaxy102
Copy link

A better way would have been:

try:
    kc_group = keycloak_admin.get_group_by_path(path="/group")
except KeycloakGetError as e:
    if e.response_code != 404:
        raise
    else:
        kc_group = None

At least that's what I've used for a long time. With the fix from #627 I now have to do

kc_group = keycloak_admin.get_group_by_path(path="/group")
if ("error", "Group path does not exist") in kc_group.items():
    kc_group = None

which feels a bit wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants