Opened 17 years ago

Closed 16 years ago

#7252 closed (duplicate)

Non-default managers inherited from an abstract model don't function.

Reported by: floguy Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Given these models:

class NaiveHierarchyManager(models.Manager):
    def get_roots(self):
        return self.get_query_set().filter(parent__isnull=True)

class NaiveHierarchy(models.Model):
    parent = models.ForeignKey('self', null=True)
    
    tree = NaiveHierarchyManager()
    
    class Meta:
        abstract = True

class BlogPost(NaiveHierarchy):
    title = models.CharField(max_length = 128)
    body = models.TextField()
    
    objects = models.Manager()
    
    def __unicode__(self):
        return self.title

What happens is that the 'tree' manager gets assigned correctly to BlogPost, but the manager's 'model' attribute still points to NaiveHierarchy, which is not the correct model. Upon trying to use the manager through BlogPost, it gives an AttributeError, complaining that the attribute _join_cache doesn't exist on NaiveHierarchy (which it shouldn't).

I've attached a patch which fixes the problem in all cases, and I can't think of a reason why it wouldn't work, but it seems like the problem is better solved elsewhere. However, all attempts on my part to fix the problem elsewhere I ran into snags. (!Manager's .model isn't set by the time ModelBase.__new__ gets called, etc).

Attachments (1)

inheritance_manager_fix.diff (553 bytes ) - added by floguy 17 years ago.

Download all attachments as: .zip

Change History (2)

by floguy, 17 years ago

comment:1 by Sebastian Noack, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #7154

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