Skip to content

Commit bf7fcc4

Browse files
committed
Raise validation error on invalid timezone parsing.
1 parent 3dab905 commit bf7fcc4

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

rest_framework/fields.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,18 +1137,16 @@ def to_internal_value(self, value):
11371137
if input_format.lower() == ISO_8601:
11381138
try:
11391139
parsed = parse_datetime(value)
1140-
except (ValueError, TypeError):
1141-
pass
1142-
else:
11431140
if parsed is not None:
11441141
return self.enforce_timezone(parsed)
1142+
except (ValueError, TypeError):
1143+
pass
11451144
else:
11461145
try:
11471146
parsed = self.datetime_parser(value, input_format)
1147+
return self.enforce_timezone(parsed)
11481148
except (ValueError, TypeError):
11491149
pass
1150-
else:
1151-
return self.enforce_timezone(parsed)
11521150

11531151
humanized_format = humanize_datetime.datetime_formats(input_formats)
11541152
self.fail('invalid', format=humanized_format)

tests/test_fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ class TestDateTimeField(FieldValues):
11521152
invalid_inputs = {
11531153
'abc': ['Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'],
11541154
'2001-99-99T99:00': ['Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'],
1155+
'2018-08-16 22:00-24:00': ['Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].'],
11551156
datetime.date(2001, 1, 1): ['Expected a datetime but got a date.'],
11561157
}
11571158
outputs = {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy