Fixed #28202 -- Fixed FieldListFilter.get_queryset() crash on invalid input.
This commit is contained in:
parent
7f238097c0
commit
4ad2f86284
|
@ -132,7 +132,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`).
|
||||
|
|
|
@ -6,6 +6,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
|
||||
|
@ -763,6 +764,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)
|
||||
|
||||
|
|
|
@ -165,7 +165,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