#36865: Query casting introduced in Django 5.2 makes queries miss DB indexes
-------------------------------------+-------------------------------------
Reporter: Mike Lissner | Type: Bug
Status: new | Component:
| contrib.admin
Version: 6.0 | Severity: Normal
Keywords: search, regression | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
https://code.djangoproject.com/ticket/26001 from 10 years ago was fixed in
PR
https://github.com/django/django/pull/17885/, which was released in
Django 5.2.
Unfortunately, this fix casts all admin search queries to varchar, which
makes the query miss the DB index instead of using it. In large tables,
this results in the query timing out, as documented as a comment on the
original issue:
https://code.djangoproject.com/ticket/26001#comment:24
And in my project's issue tracker:
https://github.com/freelawproject/courtlistener/issues/6790
We're fixing this in our system by patching the `get_search_results`
method:
https://github.com/freelawproject/courtlistener/pull/6792
I'm not at all familiar with this part of Django, but I spent some time
with claude and I think I have a fix here:
https://github.com/django/django/pull/20538
I did my best to be surgical and to add tests, but, again, this is foreign
stuff to me. I hope this helps.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36865>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.