Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Julien Phalip authored
9  django/contrib/admin/filters.py
@@ -8,13 +8,13 @@
8 8
 import datetime
9 9
 
10 10
 from django.db import models
11  
-from django.core.exceptions import ImproperlyConfigured
  11
+from django.core.exceptions import ImproperlyConfigured, ValidationError
12 12
 from django.utils.encoding import smart_text
13 13
 from django.utils.translation import ugettext_lazy as _
14 14
 from django.utils import timezone
15  
-
16 15
 from django.contrib.admin.util import (get_model_from_relation,
17 16
     reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)
  17
+from django.contrib.admin.options import IncorrectLookupParameters
18 18
 
19 19
 class ListFilter(object):
20 20
     title = None  # Human-readable title to appear in the right sidebar.
@@ -129,7 +129,10 @@ def has_output(self):
129 129
         return True
130 130
 
131 131
     def queryset(self, request, queryset):
132  
-        return queryset.filter(**self.used_parameters)
  132
+        try:
  133
+            return queryset.filter(**self.used_parameters)
  134
+        except ValidationError as e:
  135
+            raise IncorrectLookupParameters(e)
133 136
 
134 137
     @classmethod
135 138
     def register(cls, test, list_filter_class, take_priority=False):
2  tests/regressiontests/admin_views/admin.py
@@ -130,7 +130,7 @@ def changelist_view(self, request):
130 130
 
131 131
 
132 132
 class ThingAdmin(admin.ModelAdmin):
133  
-    list_filter = ('color__warm', 'color__value')
  133
+    list_filter = ('color__warm', 'color__value', 'pub_date',)
134 134
 
135 135
 
136 136
 class InquisitionAdmin(admin.ModelAdmin):
1  tests/regressiontests/admin_views/models.py
@@ -128,6 +128,7 @@ class Meta:
128 128
 class Thing(models.Model):
129 129
     title = models.CharField(max_length=20)
130 130
     color = models.ForeignKey(Color, limit_choices_to={'warm': True})
  131
+    pub_date = models.DateField(blank=True, null=True)
131 132
     def __str__(self):
132 133
         return self.title
133 134
 
4  tests/regressiontests/admin_views/tests.py
@@ -436,6 +436,10 @@ def testIncorrectLookupParameters(self):
436 436
         response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
437 437
         self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
438 438
 
  439
+        # Regression test for #18530
  440
+        response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'pub_date__gte': 'foo'})
  441
+        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
  442
+
439 443
     def testIsNullLookups(self):
440 444
         """Ensure is_null is handled correctly."""
441 445
         Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())

0 notes on commit c555741

Please sign in to comment.
Something went wrong with that request. Please try again.