#7588 closed (fixed)
Inheritance of models seems to fail when mixing abstract and multi table classes
Reported by: | zobbo | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | model inheritance | |
Cc: | flosch | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Execute the following with the following models table
pi = PlayableItem(funfactor=33,code='PS2',description='Play station 2')
You'll get the error back
TypeError: 'code' is an invalid keyword argument for this function
models.py is
from django.db import models import datetime class BaseModel(models.Model): """Abstract class used for some common fields""" created_at = models.DateTimeField(blank=True, default=datetime.datetime.now) modified_at = models.DateTimeField(blank=True, default=datetime.datetime.now) class Meta: abstract = True class Item(BaseModel): """Everything in the system - multi table inheritance""" code = models.CharField(blank=True, max_length=15) # A shortname description = models.CharField(blank=True, max_length=50) class ValuedItem(Item): """This is an abstract base class for stuff with a value""" value = models.FloatField(default=0.0) class Meta: abstract = True class PlayableItem(ValuedItem): """Inheriting from our abstract ValuedItem class""" funfactor = models.IntegerField(blank=True, null=True) # Amount of fun
This is a simplified mockup of something I was trying to do for real with various abstract and multi table classes. I made this test version just to reproduce and report the error. Having enquired in django-users was advised to file a bug report.
This is with checkout from svn - Revision: 7811. psycopg2 backend. python2.5
Attachments (2)
Change History (12)
by , 16 years ago
Attachment: | 7588.naive.diff added |
---|
comment:1 by , 16 years ago
comment:2 by , 16 years ago
milestone: | → 1.0 |
---|
comment:3 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
follow-up: 5 comment:4 by , 16 years ago
milestone: | 1.0 → post-1.0 |
---|
Could somebody verify whether this is still an issue? I'm punting for now, but if it is still a bug and somebody higher up thinks it's critical enough, we can move back to 1.0.
comment:5 by , 16 years ago
Replying to ubernostrum:
Could somebody verify whether this is still an issue? I'm punting for now, but if it is still a bug and somebody higher up thinks it's critical enough, we can move back to 1.0.
Yes, it is still a bug, and it's crawling up my behind right now.
It gives a rather nasty feeling so if you could, please try to fix it. :)
comment:6 by , 16 years ago
Has patch: | set |
---|---|
Needs tests: | set |
For convenience, I have adjusted to patch for the current trunk release (r8914) and have confirmed that it is actually working.
comment:7 by , 16 years ago
milestone: | post-1.0 → 1.0 |
---|
I'll look at this for 1.0. It needs a test case, for a start.
comment:8 by , 16 years ago
Cc: | added |
---|
comment:9 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
A minimal example:
The attached patch works for me, but It's probably incomplete. Is diamond inheritance supported (and how)?