Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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 emulbreh 6 years ago.
7588.naive.r8914.diff (692 bytes) - added by dokterbob 6 years ago.
'Naive' patch, updated to r8914.

Download all attachments as: .zip

Change History (12)

Changed 6 years ago by emulbreh

comment:1 Changed 6 years ago by emulbreh

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

  • milestone set to 1.0

comment:3 Changed 6 years ago by ericholscher

  • Triage Stage changed from Unreviewed to Accepted

comment:4 follow-up: Changed 6 years ago by ubernostrum

  • milestone changed from 1.0 to 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 in reply to: ↑ 4 Changed 6 years ago by dokterbob

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 6 years ago by dokterbob

  • 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 6 years ago by dokterbob

'Naive' patch, updated to r8914.

comment:7 Changed 6 years ago by mtredinnick

  • milestone changed from post-1.0 to 1.0

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

comment:8 Changed 6 years ago by flosch

  • Cc flosch added

comment:9 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:10 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.