From b9782b6850a032d20c321b960f4e829ed873d418 Mon Sep 17 00:00:00 2001 From: raphaelmerx Date: Wed, 2 Sep 2015 16:47:50 -0700 Subject: [PATCH] DurationField accepts integers --- rest_framework/fields.py | 2 +- tests/test_fields.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index faf41e7a0..159784ea3 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1189,7 +1189,7 @@ class DurationField(Field): def to_internal_value(self, value): if isinstance(value, datetime.timedelta): return value - parsed = parse_duration(value) + parsed = parse_duration(six.text_type(value)) if parsed is not None: return parsed self.fail('invalid', format='[DD] [HH:[MM:]]ss[.uuuuuu]') diff --git a/tests/test_fields.py b/tests/test_fields.py index 8065c8260..c1d3e3a49 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1069,6 +1069,7 @@ class TestDurationField(FieldValues): '3 08:32:01.000123': datetime.timedelta(days=3, hours=8, minutes=32, seconds=1, microseconds=123), '08:01': datetime.timedelta(minutes=8, seconds=1), datetime.timedelta(days=3, hours=8, minutes=32, seconds=1, microseconds=123): datetime.timedelta(days=3, hours=8, minutes=32, seconds=1, microseconds=123), + 3600: datetime.timedelta(hours=1), } invalid_inputs = { 'abc': ['Duration has wrong format. Use one of these formats instead: [DD] [HH:[MM:]]ss[.uuuuuu].'],