Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #3293 -- newforms: Changed IntegerField.clean() to return None …

…if field is not required and empty. Thanks, Honza Kral

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4312 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6b31f95516e3a65f93a9ab6491c6e3b2b54ae620 1 parent a0137c4
@adrianholovaty adrianholovaty authored
View
4 django/newforms/fields.py
@@ -114,11 +114,11 @@ def __init__(self, max_value=None, min_value=None, required=True, widget=None, l
def clean(self, value):
"""
Validates that int() can be called on the input. Returns the result
- of int().
+ of int(). Returns None for empty values.
"""
super(IntegerField, self).clean(value)
if not self.required and value in EMPTY_VALUES:
- return u''
+ return None
try:
value = int(value)
except (ValueError, TypeError):
View
6 tests/regressiontests/forms/tests.py
@@ -810,9 +810,11 @@
>>> f = IntegerField(required=False)
>>> f.clean('')
-u''
+>>> repr(f.clean(''))
+'None'
>>> f.clean(None)
-u''
+>>> repr(f.clean(None))
+'None'
>>> f.clean('1')
1
>>> isinstance(f.clean('1'), int)
Please sign in to comment.
Something went wrong with that request. Please try again.