#23727: IntegrityError with TransactionTestCase and sqlite
-----------------------------------+------------------------------------
     Reporter:  tctimmeh           |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  1.7
     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
-----------------------------------+------------------------------------

Comment (by khoobks):

 I realise that this is '''not a good workaround''' but as a temporary
 measure I found that the following works in my situation.

 I subclassed the TransactionTestCase and added the following code.

 {{{#!python
 def _fixture_setup(self):
         super(MyTransactionTestCase, self)._fixture_setup()
         for app_config in apps.get_app_configs():
             update_contenttypes(app_config)
             create_permissions(app_config)
             create_default_site(app_config)

     def _fixture_teardown(self):
         signals.post_migrate.disconnect(create_default_site,
 sender=apps.get_app_config('sites'))
         signals.post_migrate.disconnect(update_contenttypes)
         signals.post_migrate.disconnect(create_permissions,
 dispatch_uid="django.contrib.auth.management.create_permissions")
         signals.post_migrate.disconnect(update_group_permissions)

         super(MyTransactionTestCase, self)._fixture_teardown()

         signals.post_migrate.connect(update_contenttypes)
         signals.post_migrate.connect(create_permissions,
 dispatch_uid="django.contrib.auth.management.create_permissions")
         signals.post_migrate.connect(create_default_site,
 sender=apps.get_app_config('sites'))
 }}}

 The the overridden  {{{_fixture_teardown}}} disables the
 {{{post_migrate}}} signal handlers from executing and creating the
 problematic rows in the database. This allows the
 {{{TransactionTestCase}}} to successfully reload the original database
 state. The handlers are then manually invoked in the overriden
 {{{_fixture_setup}}} in order to ensure that for subsequent tests, the
 ContentTypes, Sites and Permissions are available.

--
Ticket URL: <https://code.djangoproject.com/ticket/23727#comment:2>
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/066.5725d8742014abb0c90676264fe7c7e2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to