Opened 7 years ago

Closed 7 years ago

#28895 closed Bug (duplicate)

serialized_rollback = True causes an IntgrityError in LiveServerTestCase

Reported by: Lyra2108 Owned by: nobody
Component: Testing framework Version: 1.8
Severity: Normal Keywords: LiveServerTestCase
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hey,

the project I am working on creates a set of required objects e.g. Groups,... within the database migrations. I would like this data also do be present, when I use LiveServerTestCases. But if I run the simple example below the 2nd test fails while the first is successful.
If serialized_rollback = False, the tests fails like expected with a "DoesNotExist: Group matching query does not exist." exception.
But if it is set to True, the exception changes to an integrity exception:

IntegrityError: duplicate key value violates unique constraint "django_content_type_app_label_45f3b1d93ec8c61c_uniq"
DETAIL:  Key (app_label, model)=(contenttypes, contenttype) already exists.

Testcase:

from django.conf import settings
from django.contrib.auth.models import Group
from django.contrib.staticfiles.testing import StaticLiveServerTestCase


class Test(StaticLiveServerTestCase):
    serialized_rollback = True

    @classmethod
    def setUpClass(cls):
        super(Test, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(Test, cls).tearDownClass()

    def test_abc(self):
        group = Group.objects.get(name='groupname')
        assert group

    def test_def(self):
        group = Group.objects.get(name='groupname')
        assert group

Change History (1)

comment:1 by Tim Graham, 7 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #23727. Fixed in Django 1.9+ by d3fdaf907db6a5be4d0391532d7e65688c19e851. In the future, please try to verify bugs against the most recent Django release.

Note: See TracTickets for help on using tickets.
Back to Top