Opened 3 weeks ago

Last modified 3 weeks ago

#36593 assigned Cleanup/optimization

Deprecate select_related() with no arguments

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, it’s possible to call select_related() with no arguments, documented thusly:

There may be some situations where you wish to call select_related() with a lot of related objects, or where you don’t know all of the relations. In these cases it is possible to call select_related() with no arguments. This will follow all non-null foreign keys it can find - nullable foreign keys must be specified. This is not recommended in most cases as it is likely to make the underlying query more complex, and return more data, than is actually needed.

In a comment thread discussing select_related() with no arguments, four contributors agreed it would be worth deprecating, due to its poor performance implications, degrading every time the given model gains a relation.

This deprecation would need to affect both select_related() with no arguments and the ModelAdmin.list_select_related = True option that uses it.

Change History (3)

comment:1 by Clifford Gama, 3 weeks ago

Triage Stage: UnreviewedAccepted

comment:2 by Adam Johnson, 3 weeks ago

Owner: set to Adam Johnson
Status: newassigned

comment:3 by Adam Johnson, 3 weeks ago

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