|
29 | 29 | from django.utils.formats import localize_input, sanitize_separators |
30 | 30 | from django.utils.ipv6 import clean_ipv6_address |
31 | 31 | from django.utils.translation import gettext_lazy as _ |
32 | | -from pytz.exceptions import InvalidTimeError |
33 | 32 |
|
34 | 33 | from rest_framework import ISO_8601 |
35 | 34 | from rest_framework.exceptions import ErrorDetail, ValidationError |
@@ -1162,15 +1161,12 @@ def enforce_timezone(self, value): |
1162 | 1161 | return value.astimezone(field_timezone) |
1163 | 1162 | except OverflowError: |
1164 | 1163 | self.fail('overflow') |
1165 | | - try: |
1166 | | - dt = timezone.make_aware(value, field_timezone) |
1167 | | - # When the resulting datetime is a ZoneInfo instance, it won't necessarily |
1168 | | - # throw given an invalid datetime, so we need to specifically check. |
1169 | | - if not valid_datetime(dt): |
1170 | | - self.fail('make_aware', timezone=field_timezone) |
1171 | | - return dt |
1172 | | - except InvalidTimeError: |
| 1164 | + dt = timezone.make_aware(value, field_timezone) |
| 1165 | + # When the resulting datetime is a ZoneInfo instance, it won't necessarily |
| 1166 | + # throw given an invalid datetime, so we need to specifically check. |
| 1167 | + if not valid_datetime(dt): |
1173 | 1168 | self.fail('make_aware', timezone=field_timezone) |
| 1169 | + return dt |
1174 | 1170 | elif (field_timezone is None) and timezone.is_aware(value): |
1175 | 1171 | return timezone.make_naive(value, datetime.timezone.utc) |
1176 | 1172 | return value |
|
0 commit comments