Opened 15 years ago

Closed 15 years ago

#11618 closed (duplicate)

Child models overwrite data of Parent model

Reported by: truebrain@… Owned by: nobody
Component: Database layer (models, ORM) 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


Given the next set of models:

class Project(models.Model):
  name = models.IntegerField()

class Subversion_Project(Project):
  revision = models.IntegerField()

class Mercurial_Project(Project):
  revision = models.CharField(max_length=64)
# This model is not used below, but it shows the intention of my database design

And the code:

project = Project(name = 1)
sproject = Subversion_Project(project_ptr = project)

The latter command overwrites the content of 'project' with all empty fields. When you print or before the save() it still is fine. After the save() it updates the project with empty values.

My solution is:

sproject = Subversion_Project(project_ptr = project)
for f in project._meta.local_fields: setattr(sproject,, getattr(project,

Which is, putting it mildly, silly. Is this a bug, or do I expect too much of the system?

Change History (1)

comment:1 by Karen Tracey, 15 years ago

Resolution: duplicate
Status: newclosed

It's a use case not currently supported by inheritance, already covered by #7623, I believe.

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