Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#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)

7588.naive.diff (640 bytes ) - added by Johannes Dollinger 16 years ago.
7588.naive.r8914.diff (692 bytes ) - added by Mathijs de Bruin 16 years ago.
'Naive' patch, updated to r8914.

Download all attachments as: .zip

Change History (12)

by Johannes Dollinger, 16 years ago

Attachment: 7588.naive.diff added

comment:1 by Johannes Dollinger, 16 years ago

A minimal example:

class A(Model):
    x = IntegerField()

class B(A):
    y = IntegerField()
    class Meta:
        abstract = True

class C(B):
    z = IntegerField()

The attached patch works for me, but It's probably incomplete. Is diamond inheritance supported (and how)?

comment:2 by anonymous, 16 years ago

milestone: 1.0

comment:3 by Eric Holscher, 16 years ago

Triage Stage: UnreviewedAccepted

comment:4 by James Bennett, 16 years ago

milestone: 1.0post-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.

in reply to:  4 comment:5 by Mathijs de Bruin, 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 Mathijs de Bruin, 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.

by Mathijs de Bruin, 16 years ago

Attachment: 7588.naive.r8914.diff added

'Naive' patch, updated to r8914.

comment:7 by Malcolm Tredinnick, 16 years ago

milestone: post-1.01.0

I'll look at this for 1.0. It needs a test case, for a start.

comment:8 by flosch, 16 years ago

Cc: flosch added

comment:9 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [8932]) Fixed #7588 -- Inherit fields from concrete ancestor classes via abstract base
classes. Based on a patch from emulbreh.

comment:10 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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