Could this go through a deprecation where any use of the inherited managers 
to be removed will raise a warning for a couple releases? If anyone is 
relying on the behavior, they just need to add the managers to any 
subclasses, correct?

On Wednesday, February 3, 2016 at 9:16:41 AM UTC-5, Alex Poleha wrote:
>
> Hi. 
>
> According to documentation 
> <https://docs.djangoproject.com/en/1.9/topics/db/managers/#custom-managers-and-model-inheritance>
>  managers 
> defined on non-abstract base classes are not inherited by child classes. In 
> fact they're inherited via python MRO. I made pull request 
> <https://github.com/django/django/pull/5797> to fix it. I find this 
> inheritance embarrassing due to reasons, explained in documentation:
>
>    1. Managers defined on non-abstract base classes are *not* inherited 
>    by child classes. If you want to reuse a manager from a non-abstract base, 
>    redeclare it explicitly on the child class. These sorts of managers are 
>    likely to be fairly specific to the class they are defined on, so 
>    inheriting them can often lead to unexpected results (particularly as far 
>    as the default manager goes). Therefore, they aren’t passed onto child 
>    classes.
>
> I also think this example shows some reasons why this inheritance is 
> embarrasing:
>
> class SimpleComment(models.Model):
>     test_objects = models.Manager()
>
>
> class BaseComment(models.Model):
>     pass
>
>
> class Comment(BaseComment):
>     test_objects = models.Manager()
>
> print(hasattr(models.SimpleComment, 'objects')) #False
> print(hasattr(models.Comment, 'objects'))  #True, we may expect False 
> here, since 'SimpleComment' gives False in similar sitation.
> print(models.Comment.objects.model) #<class 'BaseComment'>, this manager 
> is not contributed to 'Comment' class
>
> Tim Graham suggests asking if anyone relying on this inheritance and 
> documentation should be fixed instead. Any suggestions?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/4b744e92-7549-49b5-9b9b-b6158e53bb78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to