diff --git a/django_filters/filters.py b/django_filters/filters.py index 8190af82e..c2e400811 100644 --- a/django_filters/filters.py +++ b/django_filters/filters.py @@ -362,7 +362,7 @@ def get_max_validator(self): """ Return a MaxValueValidator for the field, or None to disable. """ - return MaxValueValidator(1e50) + return MaxValueValidator(int(1e50)) @property def field(self): diff --git a/tests/test_forms.py b/tests/test_forms.py index 568d7482a..51c5fe4fb 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -1,3 +1,5 @@ +from decimal import FloatOperation, getcontext + from django import forms from django.test import TestCase, override_settings @@ -267,5 +269,26 @@ class Meta: self.assertFalse(f.is_valid()) self.assertEqual( f.errors, - {'average_rating': ['Ensure this value is less than or equal to 1e+50.']} + {'average_rating': [ + 'Ensure this value is less than or equal to %d.' % int(1e50) + ]} + ) + + + def test_number_filter_max_value_validation_no_float(self): + class F(FilterSet): + class Meta: + model = Book + fields = ['average_rating'] + + ctx = getcontext() + ctx.traps[FloatOperation] = True + f = F({'average_rating': '1E1001'}) + self.assertTrue(f.is_bound) + self.assertFalse(f.is_valid()) + self.assertEqual( + f.errors, + {'average_rating': [ + 'Ensure this value is less than or equal to %d.' % int(1e50) + ]} )