[Django] #36593: Deprecate select_related() with no arguments

40 views
Skip to first unread message

Django

unread,
Sep 4, 2025, 6:29:00 AM9/4/25
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Type:
| Cleanup/optimization
Status: new | Component: Database
| layer (models, ORM)
Version: dev | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Currently, it’s possible to call `select_related()` with no arguments,
[https://docs.djangoproject.com/en/5.2/ref/models/querysets/#django.db.models.query.QuerySet.select_related
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 [https://github.com/django/django/pull/17554#discussion_r2072398386 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36593>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 4, 2025, 7:29:26 AM9/4/25
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:1>

Django

unread,
Sep 5, 2025, 10:07:31 AM9/5/25
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* owner: (none) => Adam Johnson
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:2>

Django

unread,
Sep 5, 2025, 10:12:45 AM9/5/25
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:3>

Django

unread,
Sep 29, 2025, 5:43:48 PM9/29/25
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:4>

Django

unread,
May 8, 2026, 2:57:08 PMMay 8
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:5>

Django

unread,
May 11, 2026, 12:31:45 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

As part of this work we discovered a bug in the admin where
`select_related()` was incorrectly used with the intent of "selecting all
related objects" even though it (as documented) does not follow nullable
relations. Mentioning as an additional justification for removing this
problematic use instead of doubling down on it.

For the upgrade path, the `FETCH_PEERS` fetch mode is also an option now.
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:6>

Django

unread,
May 11, 2026, 12:32:41 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"a1ead0a580bc69035b768e9fae7f92f7f0b7bf01" a1ead0a]:
{{{#!CommitTicketReference repository=""
revision="a1ead0a580bc69035b768e9fae7f92f7f0b7bf01"
Refs #36593 -- Used explicit select_related() in admin history_view().

This commit prepares for the deprecation of `QuerySet.select_related()`
with no
arguments by explicitly naming the fields to select in this view.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:9>

Django

unread,
May 11, 2026, 12:32:41 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"122f0b62a1effa558aad67a62e5b0d84a49cdc23" 122f0b6]:
{{{#!CommitTicketReference repository=""
revision="122f0b62a1effa558aad67a62e5b0d84a49cdc23"
Refs #36593 -- Deprecated setting ModelAdmin.list_select_related to True.

Now that calling `QuerySet.select_related()` without arguments is
deprecated,
this commit deprecates the corresponding admin features.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:11>

Django

unread,
May 11, 2026, 12:32:41 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"0c634de4e6950ec6fb83ab420b4af9c645b28acd" 0c634de]:
{{{#!CommitTicketReference repository=""
revision="0c634de4e6950ec6fb83ab420b4af9c645b28acd"
Refs #36593 -- Made ModelAdmin.list_select_related = False more efficient.

This change makes `list_select_related = False` avoid unnecessary joins by
only
selecting the related fields that are actually used in `list_display`.
Consequently, it avoids one code path that calls
`QuerySet.select_related()`
with no arguments, which is targeted for deprecation.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:7>

Django

unread,
May 11, 2026, 12:32:41 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"f386d8ec7cbf42b350f5958b552cd3492a493d5b" f386d8ec]:
{{{#!CommitTicketReference repository=""
revision="f386d8ec7cbf42b350f5958b552cd3492a493d5b"
Fixed #36593 -- Deprecated QuerySet.select_related() with no arguments.

This commit deprecates the "fetch all relations" form of
`QuerySet.select_related()` due to its poor performance characteristics,
and
updates several tests relying on that feature to ignore the new warning.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:10>

Django

unread,
May 11, 2026, 12:32:41 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"5ef47fccfafcbf540f870c2ee86c122cfd43a89b" 5ef47fc]:
{{{#!CommitTicketReference repository=""
revision="5ef47fccfafcbf540f870c2ee86c122cfd43a89b"
Refs #36593 -- Used explicit select_related() calls in tests.

This commit prepares for the deprecation of select_related() without
arguments
by updating tests that used select_related() as a shorthand to explicitly
specify the related fields to be selected.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:8>

Django

unread,
May 11, 2026, 12:32:42 PMMay 11
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"4de8394f2318196ad7170ae45aa142b49bb24ce4" 4de8394f]:
{{{#!CommitTicketReference repository=""
revision="4de8394f2318196ad7170ae45aa142b49bb24ce4"
Refs #36593 -- Replaced reference to select_related() in design
philosophies.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:12>

Django

unread,
Jun 17, 2026, 5:32:39 PM (2 days ago) Jun 17
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"e4527156866cb96edf881023b14cb7a6f25d7f51" e452715]:
{{{#!CommitTicketReference repository=""
revision="e4527156866cb96edf881023b14cb7a6f25d7f51"
Refs #36593 -- Added missing deprecation note for select_related() with no
arguments.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:13>

Django

unread,
Jun 17, 2026, 5:33:32 PM (2 days ago) Jun 17
to django-...@googlegroups.com
#36593: Deprecate select_related() with no arguments
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"d252a0e74bd6ad40c684e009fe8935a1c7626030" d252a0e7]:
{{{#!CommitTicketReference repository=""
revision="d252a0e74bd6ad40c684e009fe8935a1c7626030"
[6.1.x] Refs #36593 -- Added missing deprecation note for select_related()
with no arguments.

Backport of e4527156866cb96edf881023b14cb7a6f25d7f51 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36593#comment:14>
Reply all
Reply to author
Forward
0 new messages