Opened 8 years ago

Closed 8 years ago

Last modified 5 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: master
Severity: Keywords: model inheritance
Cc: flosch Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

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 8 years ago.
7588.naive.r8914.diff (692 bytes) - added by Mathijs de Bruin 8 years ago.
'Naive' patch, updated to r8914.

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by Johannes Dollinger

Attachment: 7588.naive.diff added

comment:1 Changed 8 years ago by Johannes Dollinger

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 Changed 8 years ago by anonymous

milestone: 1.0

comment:3 Changed 8 years ago by Eric Holscher

Triage Stage: UnreviewedAccepted

comment:4 Changed 8 years ago by James Bennett

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.

comment:5 in reply to:  4 Changed 8 years ago by Mathijs de Bruin

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 Changed 8 years ago by Mathijs de Bruin

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.

Changed 8 years ago by Mathijs de Bruin

Attachment: 7588.naive.r8914.diff added

'Naive' patch, updated to r8914.

comment:7 Changed 8 years ago by Malcolm Tredinnick

milestone: post-1.01.0

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

comment:8 Changed 8 years ago by flosch

Cc: flosch added

comment:9 Changed 8 years ago by Malcolm Tredinnick

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 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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