Opened 5 years ago

Closed 3 years ago

#16856 closed New feature (fixed)

Add a way to clear select_related

Reported by: carljm 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


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 aaugustin

  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 5 years ago by jdunck

  • Cc jdunck@… added

comment:3 Changed 4 years ago by seldon

  • Cc seldon added

comment:4 Changed 4 years ago by bberes

  • Cc botondus@… added

comment:5 Changed 4 years ago by bberes

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

qs.query.select_related = False

comment:7 Changed 3 years ago by timo

  • Cc timograham@… added
  • Has patch set

Added a release note & brought patch up to date.

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

  • Resolution set to fixed
  • Status changed from new to closed

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