Django

Code

Ticket #7588 (closed: fixed)

Opened 5 months ago

Last modified 3 months ago

Inheritance of models seems to fail when mixing abstract and multi table classes

Reported by: zobbo Assigned to: nobody
Milestone: 1.0 Component: Database layer (models, ORM)
Version: SVN Keywords: model inheritance
Cc: flosch Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

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

7588.naive.diff (0.6 kB) - added by emulbreh on 07/05/08 09:58:10.
7588.naive.r8914.diff (0.7 kB) - added by dokterbob on 09/03/08 07:48:34.
'Naive' patch, updated to r8914.

Change History

07/05/08 09:58:10 changed by emulbreh

  • attachment 7588.naive.diff added.

07/05/08 10:04:02 changed by emulbreh

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

07/07/08 08:33:12 changed by anonymous

  • milestone set to 1.0.

08/08/08 16:26:55 changed by ericholscher

  • stage changed from Unreviewed to Accepted.

(follow-up: ↓ 5 ) 08/22/08 17:46:23 changed 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.

(in reply to: ↑ 4 ) 09/03/08 07:37:01 changed 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. :)

09/03/08 07:47:44 changed by dokterbob

  • has_patch set to 1.
  • needs_tests set to 1.

For convenience, I have adjusted to patch for the current trunk release (r8914) and have confirmed that it is actually working.

09/03/08 07:48:34 changed by dokterbob

  • attachment 7588.naive.r8914.diff added.

'Naive' patch, updated to r8914.

09/03/08 11:42:05 changed 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.

09/03/08 11:45:20 changed by flosch

  • cc set to flosch.

09/03/08 13:38:44 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #7588 (Inheritance of models seems to fail when mixing abstract and multi table classes)




Change Properties
Action