#26749: Different manager for _base_manager and related descriptors
----------------------------------------------+---------------------
Reporter: spectras | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.10
Severity: Normal | Keywords: manager
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+---------------------
I am in the process of testing Django 1.10 and upgrading the third-party
package I maintain, django-hvad.
This ticket is related to the two following commits:
* '''Streamlined manager inheritance.:'''
https://github.com/django/django/commit/3a47d42fa33012b2156bf04058d933df6b3082d2
* '''Introduced new APIs to specify models' default and base managers:'''
https://github.com/django/django/commit/ed0ff913c648b16c4471fc9a9441d1ee48cb5420
The issue I have with the way inheritance and customization now works is
it is very hard to have a different manager as the `base_manager` and the
one used for related field descriptors.
''Why the need?''
Django-hvad is one of the modules that change the default querysets. It
does it by replacing the default manager with one that brings extra
features. Namely, automatic joining onto a translations model.
Having those features available on related fields is essential to provide
a consistent interface, and after years of having it, it is now essential
to backward compatibility as well.
It does not break the basic rule of “a base manager must not hide
objects”, as it merely adds automatic `select_related()` rules and
`iterator()` encapsulation.
Yet, those extra features cannot be on the `base_manager`, due to the way
ORM internals use it (for instance, triggering additional joins on a
delete would not work).
''Why the ticket?''
Up to Django 1.9, this was possible using `use_for_related_fields = True`,
and fixing the `_base_manager` in the `class_prepared` hook. Not clean but
workable.
With the new API though, all the manager machinery uses property
descriptors on the `Options` class, making it difficult and fragile to
override. And at the same time, using `use_for_related_fields` got
deprecated, which means there is no option to use '''a different manager
as the base manager and as the related field descriptor's manager'''
anymore.
Unless there is another way to do this?
--
Ticket URL: <https://code.djangoproject.com/ticket/26749>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.71fd66bb2f8e063f3e2e179180fd8e55%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.