#10827: django.auth create_permissions must clear the content type cache before
creating permissions
--------------------------------+------------------------------------
     Reporter:  Sean Legassick  |                    Owner:  (none)
         Type:  Bug             |                   Status:  new
    Component:  contrib.auth    |                  Version:  master
     Severity:  Normal          |               Resolution:
     Keywords:                  |             Triage Stage:  Accepted
    Has patch:  1               |      Needs documentation:  0
  Needs tests:  1               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+------------------------------------

Comment (by Michał Pasternak):

 I am having this problem with Django 1.11.5 and purest with pytest-django


 {{{
 ________________________________________________________________ ERROR at
 teardown of test_foo
 ________________________________________________________________

 self = <django.db.backends.postgresql.base.DatabaseWrapper object at
 0x10ee8e630>

     def _commit(self):
         if self.connection is not None:
             with self.wrap_database_errors:
 >               return self.connection.commit()
 E               psycopg2.IntegrityError: B����D:  wstawianie lub
 modyfikacja na tabeli "auth_permission" narusza klucz obcy
 "auth_permission_content_type_id_2f476e4b_fk_django_co"
 E               DETAIL:  Klucz (content_type_id)=(893) nie wyst��puje w
 tabeli "django_content_type".

 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/db/backends/base/base.py:236: IntegrityError

 The above exception was the direct cause of the following exception:

 self = <django.test.testcases.TransactionTestCase testMethod=__init__>

     def _post_teardown(self):
         """Performs any post-test things. This includes:

             * Flushing the contents of the database, to leave a clean
 slate. If
               the class has an 'available_apps' attribute, post_migrate
 isn't fired.
             * Force-closing the connection, so the next test gets a clean
 cursor.
             """
         try:
 >           self._fixture_teardown()

 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/test/testcases.py:925:
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 _ _ _ _ _ _
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/test/testcases.py:960: in _fixture_teardown
     inhibit_post_migrate=inhibit_post_migrate)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/core/management/__init__.py:131: in call_command
     return command.execute(*args, **defaults)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/core/management/base.py:330: in execute
     output = self.handle(*args, **options)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/core/management/commands/flush.py:88: in handle
     emit_post_migrate_signal(verbosity, interactive, database)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/core/management/sql.py:53: in emit_post_migrate_signal
     **kwargs
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/dispatch/dispatcher.py:193: in send
     for receiver in self._live_receivers(sender)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/dispatch/dispatcher.py:193: in <listcomp>
     for receiver in self._live_receivers(sender)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/contrib/auth/management/__init__.py:83: in
 create_permissions
     Permission.objects.using(using).bulk_create(perms)
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/db/models/query.py:449: in bulk_create
     obj_without_pk._state.db = self.db
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/db/transaction.py:223: in __exit__
     connection.commit()
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/db/backends/base/base.py:262: in commit
     self._commit()
 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/db/backends/base/base.py:236: in _commit
     return self.connection.commit()
 ../../envs/django-bpp/lib/python3.6/site-packages/django/db/utils.py:94:
 in __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
 ../../envs/django-bpp/lib/python3.6/site-packages/django/utils/six.py:685:
 in reraise
     raise value.with_traceback(tb)
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 _ _ _ _ _ _

 self = <django.db.backends.postgresql.base.DatabaseWrapper object at
 0x10ee8e630>

     def _commit(self):
         if self.connection is not None:
             with self.wrap_database_errors:
 >               return self.connection.commit()
 E               django.db.utils.IntegrityError: B����D:  wstawianie lub
 modyfikacja na tabeli "auth_permission" narusza klucz obcy
 "auth_permission_content_type_id_2f476e4b_fk_django_co"
 E               DETAIL:  Klucz (content_type_id)=(893) nie wyst��puje w
 tabeli "django_content_type".

 ../../envs/django-bpp/lib/python3.6/site-
 packages/django/db/backends/base/base.py:236: IntegrityError

 ===================================================================== 29
 tests deselected
 =====================================================================
 ====================================================== 1 passed, 29
 deselected, 1 error in 3.18 seconds
 =======================================================
 }}}

 My package versions
 {{{
 pytest-base-url (1.4.1)
 pytest-cov (2.5.1)
 pytest-django (3.1.2)
 pytest-html (1.16.0)
 pytest-instafail (0.3.0)
 pytest-localserver (0.3.6)
 pytest-metadata (1.5.0)
 pytest-splinter (1.8.5)
 pytest-variables (1.7.0)

 Django (1.11.5)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/10827#comment:28>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.36c80fbdef848bb5111a831a3e7858fc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to