#34165: migrate management command does not respect database parameter when 
adding
Permissions.
------------------------------+------------------------------------
     Reporter:  Vasanth       |                    Owner:  nobody
         Type:  Bug           |                   Status:  new
    Component:  contrib.auth  |                  Version:  4.1
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Accepted
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

 * component:  Migrations => contrib.auth
 * stage:  Unreviewed => Accepted


Comment:

 Thanks for this report, it's related with adding missing permissions. I
 was able to fix this by setting `_state.db`, however I'm not convinced
 that it's the best solution:
 {{{#!diff
 diff --git a/django/contrib/auth/management/__init__.py
 b/django/contrib/auth/management/__init__.py
 index 0b5a982617..27fe0df1d7 100644
 --- a/django/contrib/auth/management/__init__.py
 +++ b/django/contrib/auth/management/__init__.py
 @@ -94,12 +94,15 @@ def create_permissions(
          )
          .values_list("content_type", "codename")
      )
 -
 -    perms = [
 -        Permission(codename=codename, name=name, content_type=ct)
 -        for ct, (codename, name) in searched_perms
 -        if (ct.pk, codename) not in all_perms
 -    ]
 +    perms = []
 +    for ct, (codename, name) in searched_perms:
 +        if (ct.pk, codename) not in all_perms:
 +            permission = Permission()
 +            permission._state.db = using
 +            permission.codename = codename
 +            permission.name = name
 +            permission.content_type = ct
 +            perms.append(permission)
      Permission.objects.using(using).bulk_create(perms)
      if verbosity >= 2:
          for perm in perms:

 }}}

 Partly related to #29843.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34165#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184809c57fb-8c8f470a-d323-4f69-a43e-00f6ac512cf7-000000%40eu-central-1.amazonses.com.

Reply via email to