mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #28474 -- Made DurationField raise ValidationError for inputs that raised OverflowError.
This commit is contained in:
committed by
Tim Graham
parent
81e357a7e1
commit
55b5393bd2
@@ -469,6 +469,12 @@ class DateTimeField(BaseTemporalField):
|
||||
class DurationField(Field):
|
||||
default_error_messages = {
|
||||
'invalid': _('Enter a valid duration.'),
|
||||
'overflow': _(
|
||||
'The number of days must be between {min_days} and {max_days}.'.format(
|
||||
min_days=datetime.timedelta.min.days,
|
||||
max_days=datetime.timedelta.max.days,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def prepare_value(self, value):
|
||||
@@ -481,7 +487,10 @@ class DurationField(Field):
|
||||
return None
|
||||
if isinstance(value, datetime.timedelta):
|
||||
return value
|
||||
value = parse_duration(str(value))
|
||||
try:
|
||||
value = parse_duration(str(value))
|
||||
except OverflowError:
|
||||
raise ValidationError(self.error_messages['overflow'], code='overflow')
|
||||
if value is None:
|
||||
raise ValidationError(self.error_messages['invalid'], code='invalid')
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user