Opened 103 minutes ago
#36865 new Bug
Query casting introduced in Django 5.2 makes queries miss DB indexes
| Reported by: | Mike Lissner | Owned by: | |
|---|---|---|---|
| Component: | contrib.admin | Version: | 6.0 |
| Severity: | Normal | Keywords: | search, regression |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.