diff --git a/ssoauth/management/commands/create_custom_groups.py b/ssoauth/management/commands/create_custom_groups.py index 75708d8d9020f82790caf73bf4264c1f7147d070..8c63f5c5fbd9d1b410b1d687f086be6c904d32e9 100644 --- a/ssoauth/management/commands/create_custom_groups.py +++ b/ssoauth/management/commands/create_custom_groups.py @@ -21,11 +21,17 @@ def setup_groups(): if created: logger.info("Created group \"{}\"".format(group_name)) for perm_name in permission_names: - perm, created = Permission.objects.get_or_create( - codename=perm_name, - name=perm_name, - content_type_id=ContentType.objects.get_for_model(User).id - ) + try: + perm = Permission.objects.get( + codename=perm_name, + content_type_id=ContentType.objects.get_for_model(User).id + ) + except Permission.DoesNotExist: + perm = Permission.objects.create( + codename=perm_name, + name=perm_name, + content_type_id=ContentType.objects.get_for_model(User).id + ) if created: logger.info("Created permission \"{}\"".format(perm_name)) if perm not in group.permissions.all():