Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30751 closed Bug (needsinfo)

IntegrityError with TransactionTestCase and serialized_rollback=True.

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

Description

I experienced the same issue in #23727 (which is marked as fixed)

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "django_content_type_app_label_model_76bd3d3b_uniq"
DETAIL:  Key (app_label, model)=(admin, logentry) already exists.


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

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/test/testcases.py", line 267, in __call__
    self._pre_setup()
  File "/usr/local/lib/python3.6/site-packages/django/test/testcases.py", line 938, in _pre_setup
    self._fixture_setup()
  File "/usr/local/lib/python3.6/site-packages/django/test/testcases.py", line 987, in _fixture_setup
    connections[db_name]._test_serialized_contents
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 133, in deserialize_db_from_string
    obj.save()
  File "/usr/local/lib/python3.6/site-packages/django/core/serializers/base.py", line 223, in save
    models.Model.save_base(self.object, using=using, raw=True, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 779, in save_base
    force_update, using, update_fields,
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 870, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 908, in _do_insert
    using=using, raw=raw)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1332, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "django_content_type_app_label_model_76bd3d3b_uniq"
DETAIL:  Key (app_label, model)=(admin, logentry) already exists.

I am currently using this as a workaround:

TEST_NON_SERIALIZED_APPS = ['django.contrib.contenttypes', 'django.contrib.auth']

Change History (2)

comment:1 by Mariusz Felisiak, 5 years ago

Resolution: needsinfo
Status: newclosed
Version: 2.2master

It is definitely not exactly the same issue, because added test passes and sample project attached to the #23727 (fixed in Django 1.9) also works properly. Can you provide a sample project to reproduce your issue?

comment:2 by Mariusz Felisiak, 5 years ago

Summary: Old bug: IntegrityError with TransactionTestCase and serialized_rollback=TrueIntegrityError with TransactionTestCase and serialized_rollback=True.
Note: See TracTickets for help on using tickets.
Back to Top