Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18530 -- Fixed a small regression in the admin filters where w…

…rongly formatted dates passed as url parameters caused an unhandled ValidationError. Thanks to david for the report.
  • Loading branch information...
commit c555741aa7840d8ee4b3a191550924cca6f27105 1 parent c7f44ae
@jphalip jphalip authored
View
9 django/contrib/admin/filters.py
@@ -8,13 +8,13 @@
import datetime
from django.db import models
-from django.core.exceptions import ImproperlyConfigured
+from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
-
from django.contrib.admin.util import (get_model_from_relation,
reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)
+from django.contrib.admin.options import IncorrectLookupParameters
class ListFilter(object):
title = None # Human-readable title to appear in the right sidebar.
@@ -129,7 +129,10 @@ def has_output(self):
return True
def queryset(self, request, queryset):
- return queryset.filter(**self.used_parameters)
+ try:
+ return queryset.filter(**self.used_parameters)
+ except ValidationError as e:
+ raise IncorrectLookupParameters(e)
@classmethod
def register(cls, test, list_filter_class, take_priority=False):
View
2  tests/regressiontests/admin_views/admin.py
@@ -130,7 +130,7 @@ def changelist_view(self, request):
class ThingAdmin(admin.ModelAdmin):
- list_filter = ('color__warm', 'color__value')
+ list_filter = ('color__warm', 'color__value', 'pub_date',)
class InquisitionAdmin(admin.ModelAdmin):
View
1  tests/regressiontests/admin_views/models.py
@@ -128,6 +128,7 @@ class Meta:
class Thing(models.Model):
title = models.CharField(max_length=20)
color = models.ForeignKey(Color, limit_choices_to={'warm': True})
+ pub_date = models.DateField(blank=True, null=True)
def __str__(self):
return self.title
View
4 tests/regressiontests/admin_views/tests.py
@@ -436,6 +436,10 @@ def testIncorrectLookupParameters(self):
response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
+ # Regression test for #18530
+ response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'pub_date__gte': 'foo'})
+ self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
+
def testIsNullLookups(self):
"""Ensure is_null is handled correctly."""
Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())
Please sign in to comment.
Something went wrong with that request. Please try again.