From b1de9899739403e44bd5b9eddf50892db17461d9 Mon Sep 17 00:00:00 2001 From: Julian B Date: Tue, 12 Dec 2023 19:54:49 +0100 Subject: [PATCH] fix group creation --- myhpi/core/auth.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/myhpi/core/auth.py b/myhpi/core/auth.py index 0f24b0cd..228b2c3d 100644 --- a/myhpi/core/auth.py +++ b/myhpi/core/auth.py @@ -11,7 +11,11 @@ def _update_groups(self, user, claims): group_names = claims.get("roles", []) groups = set() for group in group_names: - groups.add(Group.objects.get_or_create(name__iexact=group)[0]) + try: + # djangos get_or_create does not work with __iexact, therefore using try/catch + groups.add(Group.objects.get(name__iexact=group)) + except Group.DoesNotExist: + groups.add(Group.objects.create(name=group)) user.groups.set(groups) def create_user(self, claims):