Opened 17 years ago

Closed 17 years ago

#7403 closed (invalid)

dumpdata do not play friendly with inheritance

Reported by: redalastor@… Owned by: nobody
Component: Core (Serialization) Version: dev
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

Description

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.save()
>>> 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:

$ ./manage.py dumpdata > yarrrr.json
$ ./manage.py reset pirates
$ ./manage.py loaddata yarrrr.json
$ ./manage.py 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 by Russell Keith-Magee, 17 years ago

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