[1.11.x] Fixed #28202 -- Fixed FieldListFilter.get_queryset() crash on invalid input.
Backport of 4ad2f86284
from master
This commit is contained in:
parent
b373812b0b
commit
a0707947e4
|
@ -135,7 +135,9 @@ class FieldListFilter(ListFilter):
|
|||
def queryset(self, request, queryset):
|
||||
try:
|
||||
return queryset.filter(**self.used_parameters)
|
||||
except ValidationError as e:
|
||||
except (ValueError, ValidationError) as e:
|
||||
# Fields may raise a ValueError or ValidationError when converting
|
||||
# the parameters to the correct type.
|
||||
raise IncorrectLookupParameters(e)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -18,3 +18,6 @@ Bugfixes
|
|||
|
||||
* Fixed an incorrect ``DisallowedModelAdminLookup`` exception when using
|
||||
a nested reverse relation in ``list_filter`` (:ticket:`28262`).
|
||||
|
||||
* Fixed admin's ``FieldListFilter.get_queryset()`` crash on invalid input
|
||||
(:ticket:`28202`).
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.contrib.admin import (
|
|||
AllValuesFieldListFilter, BooleanFieldListFilter, ModelAdmin,
|
||||
RelatedOnlyFieldListFilter, SimpleListFilter, site,
|
||||
)
|
||||
from django.contrib.admin.options import IncorrectLookupParameters
|
||||
from django.contrib.admin.views.main import ChangeList
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.contrib.auth.models import User
|
||||
|
@ -766,6 +767,13 @@ class ListFiltersTests(TestCase):
|
|||
queryset = changelist.get_queryset(request)
|
||||
self.assertEqual(list(queryset), [self.bio_book, self.djangonaut_book])
|
||||
|
||||
def test_fieldlistfilter_invalid_lookup_parameters(self):
|
||||
"""Filtering by an invalid value."""
|
||||
modeladmin = BookAdmin(Book, site)
|
||||
request = self.request_factory.get('/', {'author__id__exact': 'StringNotInteger!'})
|
||||
with self.assertRaises(IncorrectLookupParameters):
|
||||
self.get_changelist(request, Book, modeladmin)
|
||||
|
||||
def test_simplelistfilter(self):
|
||||
modeladmin = DecadeFilterBookAdmin(Book, site)
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ class CustomArticleAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
class ThingAdmin(admin.ModelAdmin):
|
||||
list_filter = ('color__warm', 'color__value', 'pub_date',)
|
||||
list_filter = ('color', 'color__warm', 'color__value', 'pub_date')
|
||||
|
||||
|
||||
class InquisitionAdmin(admin.ModelAdmin):
|
||||
|
|
Loading…
Reference in New Issue