[Django] #32649: django.contrib.admin.ModelAdmin.search_fields crashes for a search term with three quotes

28 views
Skip to first unread message

Django

unread,
Apr 13, 2021, 5:13:24 PM4/13/21
to django-...@googlegroups.com
#32649: django.contrib.admin.ModelAdmin.search_fields crashes for a search term
with three quotes
-----------------------------------------+-------------------------------
Reporter: Dlis | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Keywords: admin, search
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-------------------------------
django.contrib.admin.ModelAdmin.search_fields now allows searching against
quoted phrases with spaces but unfortunately search crashes for a search
term like **Foo "Foo "Baz"** (with three quotes, some company names match
such the pattern)

--
Ticket URL: <https://code.djangoproject.com/ticket/32649>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 13, 2021, 5:14:17 PM4/13/21
to django-...@googlegroups.com
#32649: django.contrib.admin.ModelAdmin.search_fields crashes for a search term
with three quotes
-------------------------------+--------------------------------------

Reporter: Dlis | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: admin, search | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Dlis:

Old description:

> django.contrib.admin.ModelAdmin.search_fields now allows searching
> against quoted phrases with spaces but unfortunately search crashes for a
> search term like **Foo "Foo "Baz"** (with three quotes, some company
> names match such the pattern)

New description:

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)

--

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

Django

unread,
Apr 13, 2021, 5:27:38 PM4/13/21
to django-...@googlegroups.com
#32649: django.contrib.admin.ModelAdmin.search_fields crashes for a search term
with three quotes
-------------------------------+--------------------------------------

Reporter: Dlis | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: admin, search | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Dlis):

The bag can be reproduced by the following way:

{{{
from django.utils.text import smart_split
from django.utils.text import unescape_string_literal

search_term = 'Foo "Bar "Baz"'
parts = list(smart_split(search_term))
unescape_string_literal(parts[1])
}}}

Result is {{{ValueError: Not a string literal: '"Bar "Baz'}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32649#comment:2>

Django

unread,
Apr 13, 2021, 5:59:02 PM4/13/21
to django-...@googlegroups.com
#32649: django.contrib.admin.ModelAdmin.search_fields crashes for a search term
with three quotes
-------------------------------+--------------------------------------

Reporter: Dlis | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: admin, search | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Dlis):

If somebody has such the problem, here is our temporary fix which was
added to our internal basic 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: str(t).strip('"').strip("'"), parts)
return super().get_search_results(request, queryset, ' '.join(parts))
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32649#comment:3>

Django

unread,
Apr 14, 2021, 2:51:45 AM4/14/21
to django-...@googlegroups.com
#32649: ModelAdmin.search_fields crashes for a search term with unbalanced quotes.
-------------------------------------+-------------------------------------
Reporter: Dlis | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: admin, search | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Mariusz Felisiak
* status: new => assigned
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report.
#6933
Regression in 26a413507abb38f7eee4cf62f2ee9727fdc7bf8d,
Reproduced at 9760e262f85ae57df39abe2799eff48a82b14474.

--
Ticket URL: <https://code.djangoproject.com/ticket/32649#comment:4>

Django

unread,
Apr 14, 2021, 3:08:23 AM4/14/21
to django-...@googlegroups.com
#32649: ModelAdmin.search_fields crashes for a search term with unbalanced quotes.
-------------------------------------+-------------------------------------
Reporter: Dlis | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: admin, search | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14262 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32649#comment:5>

Django

unread,
Apr 14, 2021, 6:24:23 AM4/14/21
to django-...@googlegroups.com
#32649: ModelAdmin.search_fields crashes for a search term with unbalanced quotes.
-------------------------------------+-------------------------------------
Reporter: Dlis | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution: fixed
Keywords: admin, search | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"23fa29f6a6659e0f600d216de6bcb79e7f6818c9" 23fa29f6]:
{{{
#!CommitTicketReference repository=""
revision="23fa29f6a6659e0f600d216de6bcb79e7f6818c9"
Fixed #32649 -- Fixed ModelAdmin.search_fields crash when searching
against phrases with unbalanced quotes.

Thanks Dlis for the report.

Regression in 26a413507abb38f7eee4cf62f2ee9727fdc7bf8d.
}}}

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

Django

unread,
Apr 14, 2021, 6:24:36 AM4/14/21
to django-...@googlegroups.com
#32649: ModelAdmin.search_fields crashes for a search term with unbalanced quotes.
-------------------------------------+-------------------------------------
Reporter: Dlis | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution: fixed
Keywords: admin, search | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"59cce8237c9efb33f16058bac67702d5a11ea1d9" 59cce823]:
{{{
#!CommitTicketReference repository=""
revision="59cce8237c9efb33f16058bac67702d5a11ea1d9"
[3.2.x] Fixed #32649 -- Fixed ModelAdmin.search_fields crash when


searching against phrases with unbalanced quotes.

Thanks Dlis for the report.

Regression in 26a413507abb38f7eee4cf62f2ee9727fdc7bf8d.
Backport of 23fa29f6a6659e0f600d216de6bcb79e7f6818c9 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32649#comment:7>

Reply all
Reply to author
Forward
0 new messages