diff --git a/django/forms/fields.py b/django/forms/fields.py index ac615bbe68..00e9ff102b 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -488,7 +488,7 @@ class DurationField(Field): return None if isinstance(value, datetime.timedelta): return value - value = parse_duration(value) + value = parse_duration(force_str(value)) if value is None: raise ValidationError(self.error_messages['invalid'], code='invalid') return value diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 80e17881ef..1bab912cfc 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -722,6 +722,10 @@ class FieldsTests(SimpleTestCase): str(f['duration']) ) + def test_durationfield_integer_value(self): + f = DurationField() + self.assertEqual(datetime.timedelta(0, 10800), f.clean(10800)) + def test_durationfield_prepare_value(self): field = DurationField() td = datetime.timedelta(minutes=15, seconds=30)