[Django] #37187: Extraneous and confusing ModelAdmin select_related deprecation warnings

10 views
Skip to first unread message

Django

unread,
Jun 24, 2026, 7:55:59 PM (6 days ago) Jun 24
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike | Owner: Mike Edmunds
Edmunds |
Type: Bug | Status: assigned
Component: | Version: 6.1
contrib.admin | Keywords: ModelAdmin,
Severity: Normal | deprecation
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Some of the deprecation warnings introduced in
122f0b62a1effa558aad67a62e5b0d84a49cdc23 (as a follow-up to #36593):
* Are issued against Django internals or wsgiref/handlers.py (or whatever
code is serving the admin site)—''not'' against the code that is
responsible for the deprecated behavior.
* Sometimes include an extra warning that "Calling select_related() with
no arguments is deprecated," even though select_related() is not called
anywhere in the user's code.

To reproduce (Django 6.1b1, run with `PYTHONWARNINGS=always` to see all
deprecations):
1. Have a `models.Author` and `models.Book` with a foreign key to author.
2. Define `admin.BookAdmin` with a `get_select_related()` method that
returns the deprecated value `True`:
{{{#!python
from django.contrib import admin
from .models import Author, Book

class BookAdmin(admin.ModelAdmin):
list_display = ['title', 'author__name']

def get_list_select_related(self, request):
return True # deprecated return value

admin.site.register(Author)
admin.site.register(Book, BookAdmin)
}}}
3. Run the devserver and visit `/admin/yourapp/books/`

Results: the warning about returning True from get_list_select_related()
points to Django's internals, and there's an extra warning about
wsgiref/handlers.py calling select_related() with no arguments:
{{{#!text
.venv/lib/python3.14/site-packages/django/contrib/admin/options.py:930:
RemovedInDjango70Warning: Returning True from
ModelAdmin.get_list_select_related() is deprecated. Return False or a list
or tuple of fields to fetch instead.
warnings.warn(
.pyenv/versions/3.14.3/lib/python3.14/wsgiref/handlers.py:137:
RemovedInDjango70Warning: Calling select_related() with no arguments is
deprecated. Specify the fields to fetch instead.
self.result = application(self.environ, self.start_response)
}}}

Expected: ideally, something that points to the BookAdmin implementation
(and nothing about calling select_related()):
{{{#!text
.../example-project/yourapp/admin.py:7: RemovedInDjango70Warning:
Returning True from ModelAdmin.get_list_select_related() is deprecated.
Return False or a list or tuple of fields to fetch instead.
def get_list_select_related(self, request):
}}}

There are two issues here:
A. ModelAdmin.get_changelist_instance() is trying to warn about an
overridden subclass method that has already been called so is no longer on
the stack. (It's also missing `skip_file_prefixes`, which is why it's
blaming Django internals. But adding that would just move the blame to
wsgiref—still not helpful.)
B. QuerySet.select_related() is unconditionally issuing a deprecation
warning, even when it's being used internally to implement a deprecated
feature elsewhere in Django (like in ModelAdmin).

The second problem is easily solved: we implemented
`warn_about_external_use()` specifically for this use case.

The first problem is probably solvable by using `warnings.warn_explicit()`
to point to the subclass method that is actually at fault. (I'm looking
into that now.) If that doesn't work, we could change the warning message
to include the actual subclass name: `Returning True from
yourapp.admin.BookAdmin.get_list_select_related() is deprecated.`


Also:

* If you replace `BookAdmin.get_list_select_related()` with
`list_select_related = True`, you get a nice startup-time warning that
points at the `class BookAdmin` definition in your own admin.py. But you
still get the extraneous `select_related()` warning in wsgiref when
visiting the view.
* If you load the admin view from a test, the warnings will point to the
`self.client.get("/admin/core/books/")` line instead of wsgiref. (That at
least gives you some idea which code might be the problem.)
* I suspect there's a similar issue with the warning for overriding
get_actions()/get_action_choices() without the 'action_location' parameter
(from #12090 - f30acb184f75fd9260cfd6ddc48a3bbbd49f9c1d).
* The extraneous select_related() warning occurs in Django's tests, but is
being suppressed by #37072. (The PR for that issue made it visible, and
pulling that thread lead to this.)
--
Ticket URL: <https://code.djangoproject.com/ticket/37187>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 24, 2026, 7:57:53 PM (6 days ago) Jun 24
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Normal | Resolution:
Keywords: ModelAdmin, | Triage Stage:
deprecation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Mike Edmunds:

Old description:
New description:
`self.client.get("/admin/yourapp/books/")` line instead of wsgiref. (That
at least gives you some idea which code might be the problem.)
* I suspect there's a similar issue with the warning for overriding
get_actions()/get_action_choices() without the 'action_location' parameter
(from #12090 - f30acb184f75fd9260cfd6ddc48a3bbbd49f9c1d).
* The extraneous select_related() warning occurs in Django's tests, but is
being suppressed by #37072. (The PR for that issue made it visible, and
pulling that thread lead to this.)

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

Django

unread,
Jun 25, 2026, 12:12:53 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted

Comment:

Nice catch!
--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:2>

Django

unread,
Jun 25, 2026, 12:24:20 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mike Edmunds):

`warnings.warn_explicit()` works well. I'm putting together a helper
function for that, and will cover this and #37190 in the same PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:3>

Django

unread,
Jun 25, 2026, 1:55:52 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

* has_patch: 0 => 1

Comment:

https://github.com/django/django/pull/21551 is the quick fix for the extra
`select_related()` warning (problem "B").
--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:4>

Django

unread,
Jun 25, 2026, 4:47:11 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
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:"99672c672a1537aeb0d1fd5911ca6f04154cc091" 99672c6]:
{{{#!CommitTicketReference repository=""
revision="99672c672a1537aeb0d1fd5911ca6f04154cc091"
Refs #36593, #37187 -- Avoided spurious select_related() warning in
ModelAdmin.

Changed QuerySet.select_related() "called with no arguments" deprecation
warning to be issued only when called from outside Django. This prevents
a confusing, cascading warning when ModelAdmin issues its own warning
for list_select_related=True (see 122f0b62) and then calls
QuerySet.select_related() to implement the deprecated behavior.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:5>

Django

unread,
Jun 25, 2026, 4:50:27 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

* has_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:6>

Django

unread,
Jun 25, 2026, 4:50:50 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"1d20e124b3396ac38a32216f33d845b641e2e5e5" 1d20e124]:
{{{#!CommitTicketReference repository=""
revision="1d20e124b3396ac38a32216f33d845b641e2e5e5"
[6.1.x] Refs #36593, #37187 -- Avoided spurious select_related() warning
in ModelAdmin.

Changed QuerySet.select_related() "called with no arguments" deprecation
warning to be issued only when called from outside Django. This prevents
a confusing, cascading warning when ModelAdmin issues its own warning
for list_select_related=True (see 122f0b62) and then calls
QuerySet.select_related() to implement the deprecated behavior.

Backport of 99672c672a1537aeb0d1fd5911ca6f04154cc091 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:7>

Django

unread,
Jun 25, 2026, 5:47:52 PM (5 days ago) Jun 25
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:8>

Django

unread,
Jun 26, 2026, 2:17:55 PM (4 days ago) Jun 26
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
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/37187#comment:9>

Django

unread,
Jun 26, 2026, 6:06:37 PM (4 days ago) Jun 26
to django-...@googlegroups.com
#37187: Extraneous and confusing ModelAdmin select_related deprecation warnings
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Mike
| Edmunds
Type: Bug | Status: assigned
Component: contrib.admin | Version: 6.1
Severity: Release blocker | Resolution:
Keywords: ModelAdmin, | Triage Stage: Accepted
deprecation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mike Edmunds):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/37187#comment:10>
Reply all
Reply to author
Forward
0 new messages