#16509: init test db: try insert a existing permission
(django.db.utils.IntegrityError: columns content_type_id, codename are not
unique)
-------------------------------------+-------------------------------------
     Reporter:  rogeliomita@…        |                    Owner:  tobias
         Type:  Bug                  |                   Status:  reopened
    Component:                       |                  Version:  1.3
  contrib.contenttypes               |               Resolution:
     Severity:  Release blocker      |             Triage Stage:  Accepted
     Keywords:  not unique,          |      Needs documentation:  0
  permission, auth                   |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by patrick):

 * cc: patrick.craston@… (added)
 * status:  closed => reopened
 * resolution:  worksforme =>


Comment:

 Reopening this ticket as I am experiencing the same problem.

 After updating from Django 1.2.7 to 1.3.1 and running our Unit Test suite
 with sqlite, the unit tests fail with the IntegrityError mentioned in this
 ticket.

 I was able to fix the problem by moving this code block (lines 38-42,
 
[https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/contrib/auth/management/__init__.py
 source])
 {{{
 all_perms = set(auth_app.Permission.objects.filter(
             content_type__in=ctypes,
             ).values_list(
             "content_type", "codename"
             ))
 }}}
 from outside the loop (line 44,
 
[https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/contrib/auth/management/__init__.py
 source])
 {{{
 for ctype, (codename, name) in searched_perms:
 }}}
 to inside this for loop.

 This is the new code:
 {{{
 for ctype, (codename, name) in searched_perms:
         # Find all the Permissions that have a context_type for a model
 we're
         # looking for.  We don't need to check for codenames since we
 already have
         # a list of the ones we're going to create.
         ## Bug fix ##
         # Moved the following code block to inside the for loop due to
 error.
         # Problem was that permission was being set twice for apps
 specific to project. If the code is outside
         # the loop it will only check once per set of apps.
         all_perms = set(auth_app.Permission.objects.filter(
             content_type__in=ctypes,
             ).values_list(
             "content_type", "codename"
             ))

         # If the permissions exists, move on.
         if (ctype.pk, codename) in all_perms:
             continue
         p = auth_app.Permission.objects.create(
             codename=codename,
             name=name,
             content_type=ctype
         )
         if verbosity >= 2:
             print "Adding permission '%s'" % p
 }}}

 It seems like this code has changed in the Django subversion trunk, so the
 bug might have been fixed there.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16509#comment:10>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to