Opened 12 years ago

Closed 12 years ago

#7403 closed (invalid)

dumpdata do not play friendly with inheritance

Reported by: redalastor@… Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Let say I have the following classes:

class Person(models.Model):
    first_name = models.CharField(max_length = 50)
    last_name = models.CharField(max_length = 50)

    def full_name(self):
        return "%s %s" % (self.first_name, self.last_name)

class Pirate(Person):
    pastafarian = models.BooleanField(default = True)

Now I create a Pirate:

>>> p = Pirate()
>>> p.first_name = "Jack"
>>> p.last_name = "Sparrow"
>>> p.pastafarian = False
>>> p
<Pirate: Jack Sparrow>
>>> Person.objects.all()
[<Person: Jack Sparrow>]
>>> Pirate.objects.all()
[<Pirate: Jack Sparrow>]

So far so good. Lets get to the buggy part:

$ ./ dumpdata > yarrrr.json
$ ./ reset pirates
$ ./ loaddata yarrrr.json
$ ./ shell
>>> from myproject.pirates.models import *
>>> Person.objects.all()
[<Person: Jack Sparrow>, <Person: Jack Sparrow>]

A workaround for now is to manually edit the serialized file and remove all references to the base class (Person in this case). Import will then work as expected.

Change History (1)

comment:1 Changed 12 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

You don't give an SVN revision that you were using, but the behavior you are reporting is consistent with pre-[7600], when this bug was fixed. If you are still seeing this behaviour with [7600] or newer, please reopen.

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