Non-default managers inherited from an abstract model don't function.
|Reported by:||floguy||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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).