From 92815998b792e0fbf6c024a45369c3c8ba15a0ab Mon Sep 17 00:00:00 2001
From: Alex Hadula <alexander.hadula@hs-hannover.de>
Date: Sun, 12 Sep 2021 03:09:05 +0200
Subject: [PATCH] Incase migrations create the same permission twice

When upgrading from Django 2.0 to 3.2, Django decided
to create the one or other permission with the exact
same name but with a different content_type!

That's why we needed to ensure 'our' content_type
is the one we want to get and not the duplicate from
django!
---
 .../management/commands/ssoauth_setup_groups_and_perms.py    | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ssoauth/management/commands/ssoauth_setup_groups_and_perms.py b/ssoauth/management/commands/ssoauth_setup_groups_and_perms.py
index 4c74434..7bc2828 100644
--- a/ssoauth/management/commands/ssoauth_setup_groups_and_perms.py
+++ b/ssoauth/management/commands/ssoauth_setup_groups_and_perms.py
@@ -16,13 +16,14 @@ def get_or_create_permission(codename, create_with_name=None):
     :return: permission object
     Ensures the permissions exists. Creates it if needed.
     """
+    user_content_type = get_user_content_type()
     try:
-        perm = Permission.objects.get(codename=codename)
+        perm = Permission.objects.get(codename=codename, content_type=user_content_type)
     except Permission.DoesNotExist:
         perm = Permission.objects.create(
             codename=codename,
             name=create_with_name or codename,
-            content_type=get_user_content_type()
+            content_type=user_content_type
         )
         logger.info("Created permission: {0}".format(perm))
     return perm
-- 
GitLab