Re: [Django] #36865: Casting on __exact searches over non-text fields in admin misses indexes

2 views
Skip to first unread message

Django

unread,
Jan 30, 2026, 11:45:49 AM (6 days ago) Jan 30
to django-...@googlegroups.com
#36865: Casting on __exact searches over non-text fields in admin misses indexes
-------------------------------------+-------------------------------------
Reporter: Mike Lissner | Owner: Mike
| Lissner
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution: fixed
Keywords: search_fields cast | 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:"4cecf3039586ea738afafb9a28c946bff42c37c1" 4cecf303]:
{{{#!CommitTicketReference repository=""
revision="4cecf3039586ea738afafb9a28c946bff42c37c1"
Fixed #36865 -- Removed casting from exact lookups in admin searches.

Instead of casting non-text fields to CharField (which prevents index
usage), skip exact lookups when the search term fails
formfield.to_python().

This preserves index usage for valid searches while gracefully handling
invalid search terms by simply not including them in the query for that
field.

For multi-term searches like 'foo 123' on search_fields=['name',
'age__exact']:
- 'foo': invalid for age, so only name lookup is used
- '123': valid for both, so both lookups are used

This entails a slight increase in permissiveness for search terms that
can be normalized by formfield.to_python().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36865#comment:14>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 30, 2026, 11:45:50 AM (6 days ago) Jan 30
to django-...@googlegroups.com
#36865: Casting on __exact searches over non-text fields in admin misses indexes
-------------------------------------+-------------------------------------
Reporter: Mike Lissner | Owner: Mike
| Lissner
Type: Bug | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: search_fields cast | 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:"b25bc2441827a31b5629e9f79ad7296b992648a2" b25bc24]:
{{{#!CommitTicketReference repository=""
revision="b25bc2441827a31b5629e9f79ad7296b992648a2"
Refs #36865 -- Added test for invalid value handling in admin changelist.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36865#comment:13>

Django

unread,
Jan 31, 2026, 11:49:11 AM (5 days ago) Jan 31
to django-...@googlegroups.com
#36865: Casting on __exact searches over non-text fields in admin misses indexes
-------------------------------------+-------------------------------------
Reporter: Mike Lissner | Owner: Mike
| Lissner
Type: Bug | Status: closed
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution: fixed
Keywords: search_fields cast | 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:"674eda1c03a3187905f48afee0f15226aa62fdf3" 674eda1c]:
{{{#!CommitTicketReference repository=""
revision="674eda1c03a3187905f48afee0f15226aa62fdf3"
Refs #36865 -- Fixed
test_exact_lookup_validates_each_field_independently() crash on databases
that don't support primitives in JSONFields.

For example on Oracle < 21c.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36865#comment:15>
Reply all
Reply to author
Forward
0 new messages