diff --git a/django/forms/fields.py b/django/forms/fields.py index c50cd164ed..8a534e7bb5 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -275,7 +275,7 @@ class IntegerField(Field): value = formats.sanitize_separators(value) # Strip trailing decimal and zeros. try: - value = int(self.re_decimal.sub('', str(value))) + value = int(self.re_decimal.sub('', force_text(value))) except (ValueError, TypeError): raise ValidationError(self.error_messages['invalid'], code='invalid') return value diff --git a/tests/forms_tests/field_tests/test_integerfield.py b/tests/forms_tests/field_tests/test_integerfield.py index d5c14857ed..cd648279a6 100644 --- a/tests/forms_tests/field_tests/test_integerfield.py +++ b/tests/forms_tests/field_tests/test_integerfield.py @@ -123,6 +123,10 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase): self.assertEqual(9223372036854775808, f.clean('9223372036854775808')) self.assertEqual(9223372036854775808, f.clean('9223372036854775808.0')) + def test_integerfield_unicode_number(self): + f = IntegerField() + self.assertEqual(50, f.clean('50')) + def test_integerfield_subclass(self): """ Class-defined widget is not overwritten by __init__() (#22245).