Code

Ticket #16385: e9cb952ff9052caa223dfa90529d869c00108674.diff

File e9cb952ff9052caa223dfa90529d869c00108674.diff, 1.0 KB (added by jonash, 3 years ago)

Permission creation __in

Line 
1diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
2index 46dbea8..5f625aa 100644
3--- a/django/contrib/auth/management/__init__.py
4+++ b/django/contrib/auth/management/__init__.py
5@@ -35,11 +35,12 @@ def create_permissions(app, created_models, verbosity, **kwargs):
6     # Find all the Permissions that have a context_type for a model we're
7     # looking for.  We don't need to check for codenames since we already have
8     # a list of the ones we're going to create.
9-    all_perms = set(auth_app.Permission.objects.filter(
10-        content_type__in=ctypes,
11-    ).values_list(
12-        "content_type", "codename"
13-    ))
14+    all_perms = set()
15+    ctypes_pks = set(ct.pk for ct in ctypes)
16+    for ctype, codename in auth_app.Permission.objects.all().values_list(
17+            'content_type', 'codename')[:1000000]:
18+        if ctype in ctypes_pks:
19+            all_perms.add((ctype, codename))
20 
21     for ctype, (codename, name) in searched_perms:
22         # If the permissions exists, move on.