Django

Code

Ticket #7202 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

fixture loading fails for one-to-one relations

Reported by: zhaoz Assigned to: nobody
Milestone: Component: Serialization
Version: SVN Keywords:
Cc: zilingzhao@gmail.com Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

Models created with one-to-one relation as documented fail to produce loadable fixtures.

Fixtures created with dumpdata and then reloaded with loaddata fail with this error:

ERROR:  duplicate key violates unique constraint "App_model_pkey"

Tested with dumpdata using json on postgresql.


Also tested on sqlite

Models:

from django.db import models

# Create your models here.
class Parent(models.Model):
    name = models.CharField(max_length=60, unique=True)

class Child(Parent):
    parent = models.OneToOneField(Parent, parent_link=True)
    number = models.IntegerField(max_length=20)

Dumpdata

$ ./manage.py dumpdata --format=json first > first/fixtures/test.json
$ cat first/fixtures/test.json
[{"pk": 1, "model": "first.parent", "fields": {"name": "first1"}}, {"pk": 1, "model": "first.child", "fields": {"name": "first1", "number": 2}}]
$ ./manage.py loaddata test
Installing json fixture 'test' from '/home/zhaoz/programming/python/django_test/onetoone/../onetoone/first/fixtures'.
Problem installing fixture '/home/zhaoz/programming/python/django_test/onetoone/../onetoone/first/fixtures/test.json': column name is not unique

Attachments

onetoone_fixtures_test_r7526.patch (1.1 kB) - added by zhaoz on 05/13/08 18:15:14.
Adds a test for onetoone fixture loading -- (needs the onetoone.json fixture)
onetoone.json (237 bytes) - added by zhaoz on 05/13/08 18:15:49.
The fixture to be used with the onetoone test.
onetoone_fixtures_test_r7526.diff (1.1 kB) - added by zhaoz on 05/15/08 19:00:23.
Renamed the .patch to .diff
o2o_fixture_load_r7540.diff (0.7 kB) - added by zhaoz on 05/19/08 16:44:09.
The fix, sets parent's pk so update/save new works correctly.

Change History

05/08/08 17:41:46 changed by zhaoz

  • cc set to zilingzhao@gmail.com.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

05/13/08 18:15:14 changed by zhaoz

  • attachment onetoone_fixtures_test_r7526.patch added.

Adds a test for onetoone fixture loading -- (needs the onetoone.json fixture)

05/13/08 18:15:49 changed by zhaoz

  • attachment onetoone.json added.

The fixture to be used with the onetoone test.

05/15/08 19:00:23 changed by zhaoz

  • attachment onetoone_fixtures_test_r7526.diff added.

Renamed the .patch to .diff

05/19/08 16:44:09 changed by zhaoz

  • attachment o2o_fixture_load_r7540.diff added.

The fix, sets parent's pk so update/save new works correctly.

05/19/08 16:44:53 changed by zhaoz

  • has_patch set to 1.
  • component changed from Database wrapper to Serialization.

05/20/08 16:11:50 changed by zhaoz

  • needs_better_patch set to 1.

Patch actually fails for some cases. Will need to look at patch/test case.

05/20/08 16:12:01 changed by zhaoz

  • needs_better_patch deleted.
  • has_patch deleted.

05/20/08 17:10:20 changed by zhaoz

  • needs_better_patch set to 1.
  • has_patch set to 1.

The patch works for every case with the exception of when the parent model and the child model share the same pk field name.

06/09/08 09:03:35 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [7600]) Fixed #7350, #7202 -- Fixed serialization for multi-model inheritance, which had multiple problems:

  • Serializers were including all superclass fields in their output. Now only local fields are included.
  • Implicit OneToOne? primary keys were not correctly added to the metamodel, so they were always marked to be serialized, even though they were primary
  • Model saving was too aggressive about creating new parent class instances during deserialization. Raw save on a model now skips saving of the parent class.

Add/Change #7202 (fixture loading fails for one-to-one relations)




Change Properties
Action