Skip to content

Commit 2ecfc94

Browse files
committed
Removed try-except
1 parent b817c82 commit 2ecfc94

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

rest_framework/compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
The `compat` module provides support for backwards compatibility with older
33
versions of Django/Python, and compatibility wrappers around optional packages.
44
"""
5+
import django
56
from django.views.generic import View
67

78

rest_framework/fields.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,15 +1172,12 @@ def enforce_timezone(self, value):
11721172
return value.astimezone(field_timezone)
11731173
except OverflowError:
11741174
self.fail('overflow')
1175-
try:
1176-
dt = timezone.make_aware(value, field_timezone)
1177-
# When the resulting datetime is a ZoneInfo instance, it won't necessarily
1178-
# throw given an invalid datetime, so we need to specifically check.
1179-
if not valid_datetime(dt):
1180-
self.fail('make_aware', timezone=field_timezone)
1181-
return dt
1182-
except Exception as e:
1183-
raise e
1175+
dt = timezone.make_aware(value, field_timezone)
1176+
# When the resulting datetime is a ZoneInfo instance, it won't necessarily
1177+
# throw given an invalid datetime, so we need to specifically check.
1178+
if not valid_datetime(dt):
1179+
self.fail('make_aware', timezone=field_timezone)
1180+
return dt
11841181
elif (field_timezone is None) and timezone.is_aware(value):
11851182
return timezone.make_naive(value, datetime.timezone.utc)
11861183
return value

0 commit comments

Comments
 (0)