#23640: StaticLiveServerTestCase does not properly respect data migrations
-------------------------------------+-------------------------------------
     Reporter:  eldamir              |                    Owner:  gchp
         Type:  Bug                  |                   Status:  closed
    Component:  Testing framework    |                  Version:  1.7
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:  data migration,      |             Triage Stage:  Accepted
  functional tests                   |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by eldamir):

 I do get another error now when using the solution mentioned above, which
 seems a bit weird too.

 After the first test case runs, before getting to the setUp method of the
 second test case, I get

 {{{
 Error
 Traceback (most recent call last):
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/backends/utils.py", line 65, in execute
     return self.cursor.execute(sql, params)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/backends/sqlite3/base.py", line 486, in execute
     return Database.Cursor.execute(self, query, params)
 sqlite3.IntegrityError: UNIQUE constraint failed:
 django_content_type.app_label, django_content_type.model

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

 Traceback (most recent call last):
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/test/testcases.py", line 182, in __call__
     self._pre_setup()
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/test/testcases.py", line 754, in _pre_setup
     self._fixture_setup()
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/test/testcases.py", line 797, in _fixture_setup
     connections[db_name]._test_serialized_contents
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/backends/creation.py", line 428, in
 deserialize_db_from_string
     obj.save()
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/core/serializers/base.py", line 173, in save
     models.Model.save_base(self.object, using=using, raw=True)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/models/base.py", line 618, in save_base
     updated = self._save_table(raw, cls, force_insert, force_update,
 using, update_fields)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/models/base.py", line 699, in _save_table
     result = self._do_insert(cls._base_manager, using, fields, update_pk,
 raw)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/models/base.py", line 732, in _do_insert
     using=using, raw=raw)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/models/manager.py", line 92, in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/models/query.py", line 921, in _insert
     return query.get_compiler(using=using).execute_sql(return_id)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/models/sql/compiler.py", line 920, in execute_sql
     cursor.execute(sql, params)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/backends/utils.py", line 65, in execute
     return self.cursor.execute(sql, params)
   File "/home/ruben/v3env/lib/python3.4/site-packages/django/db/utils.py",
 line 94, in __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/utils/six.py", line 549, in reraise
     raise value.with_traceback(tb)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/backends/utils.py", line 65, in execute
     return self.cursor.execute(sql, params)
   File "/home/ruben/v3env/lib/python3.4/site-
 packages/django/db/backends/sqlite3/base.py", line 486, in execute
     return Database.Cursor.execute(self, query, params)
 django.db.utils.IntegrityError: UNIQUE constraint failed:
 django_content_type.app_label, django_content_type.model
 }}}


 What seems to cause this is some automatically generated SQL calls from
 Django:

 {{{
 UPDATE "django_content_type" SET "name" = ?, "app_label" = ?, "model" = ?
 WHERE "django_content_type"."id" = ? ('log entry', 'admin', 'logentry', 1)
 INSERT INTO "django_content_type" ("id", "name", "app_label", "model")
 SELECT ? AS "id", ? AS "name", ? AS "app_label", ? AS "model" (1, 'log
 entry', 'admin', 'logentry')
 }}}

 As far as I can tell, a row is updated, setting some values, and then a
 row is inserted which violates the UNIQUE constraint.

 I don't have the insight to work around this. I will just use fixtures for
 now :(

--
Ticket URL: <https://code.djangoproject.com/ticket/23640#comment:15>
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/065.34a7b222434fc8cdbc6f2577917a8304%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to