django-model-utils
django-model-utils copied to clipboard
InheritanceManager select_subclasses ought to accept None
the ability to reset a set of select_related values finally became public API in Django 1.6, so that doing queryset.query.select_related = False is now represented and documented as queryset.select_related(None)
We should probably support that syntax, so that one can do queryset.select_subclasses(None) which would clear out the select_related values and the list of subclasses bound to the queryset in .subclasses.
The current situation is doing queryset.select_subclasses(ModelA, 'b__c').select_related(None) works, and continues to return the right objects, but at the expense of doing a single query per object (per depth), because the subclasses attribute persists.
Note that for the purposes of backwards compatibility with 1.4 and 1.5, if accepted, we'd probably still need to set query.select_related = False ourselves, as just calling select_related(None) would be an exception under previous version (because of not being able to split None by LOOKUP_SEP)
Yup.
what's the status on this?
select_subclasses().select_related() does N query for N objects...
There is no status; patch welcome. I'm not even sure what the right fix is here yet, someone needs to look into it. Ideally there would be a way we can always make sure the subclasses we need are selected, without disturbing a user select_related that occurs before or after the call to select_subclasses. If we can't manage that, an error is probably better than silently doing N queries.