Opened 5 years ago

Closed 4 years ago

#16856 closed New feature (fixed)

Add a way to clear select_related

Reported by: Carl Meyer Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: jdunck@…, seldon, botondus@…, timograham@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you've got a queryset that has had select_related called on it (maybe passed to you from some other code you don't control) there's currently no documented way to clear out select_related.

One possible API is .select_related(None), which mirrors how .defer() works.

The combination of this and #16855 would make .select_related() and .defer() more consistent with each other, which would be nice.

Change History (8)

comment:1 Changed 5 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

There was a clear consensus on this API in #django-dev.

comment:2 Changed 5 years ago by Jeremy Dunck

Cc: jdunck@… added

comment:3 Changed 5 years ago by seldon

Cc: seldon added

comment:4 Changed 4 years ago by Béres Botond

Cc: botondus@… added

comment:5 Changed 4 years ago by Béres Botond

For anyone reading this, the undocumented hacky way to do this is:

qs.query.select_related = False

comment:7 Changed 4 years ago by Tim Graham

Cc: timograham@… added
Has patch: set

Added a release note & brought patch up to date.

https://github.com/django/django/pull/1234

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 5074c75a37f88726f3ae057999144545881d3cfc:

Fixed #16856 - Added a way to clear select_related.

Thanks Carl for the suggestion and David Cramer for the patch.

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