#32649 closed Bug (fixed)
ModelAdmin.search_fields crashes for a search term with unbalanced quotes.
Reported by: | Dlis | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | contrib.admin | Version: | 3.2 |
Severity: | Release blocker | Keywords: | admin, search |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
django.contrib.admin.ModelAdmin.search_fields now allows searching against quoted phrases with spaces but unfortunately search crashes for a search term like Foo "Bar "Baz" (with three quotes, some company names match such the pattern)
Change History (7)
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:3 by , 4 years ago
If somebody has such the problem, here is our temporary fix which was added to our internal basic ModelAdmin:
from django.utils import text class ModelAdmin(...): ... def get_search_results(self, request, queryset, search_term): parts = search_term.split() try: for part in text.smart_split(search_term): text.unescape_string_literal(part) except ValueError: parts = map(lambda t: t.strip('"').strip("'"), parts) return super().get_search_results(request, queryset, ' '.join(parts))
comment:4 by , 4 years ago
Owner: | changed from | to
---|---|
Severity: | Normal → Release blocker |
Status: | new → assigned |
Summary: | django.contrib.admin.ModelAdmin.search_fields crashes for a search term with three quotes → ModelAdmin.search_fields crashes for a search term with unbalanced quotes. |
Triage Stage: | Unreviewed → Accepted |
Thanks for the report.
Regression in 26a413507abb38f7eee4cf62f2ee9727fdc7bf8d.
Reproduced at 9760e262f85ae57df39abe2799eff48a82b14474.
Note:
See TracTickets
for help on using tickets.
The bug can be reproduced by the following way:
Result is
ValueError: Not a string literal: '"Bar "Baz'