Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdba9493

Browse files
authored
Don't evaluate default_timezone unless needed (#8531)
If you set a custom timezone for a DateTimeField, the functionself.default_timezone() is still called, since fallback params togetattr are still evaluated.This rewrites to use hasattr, so the fallback case is only executed ifit will actually be used. If you render a lot of DateTimeFields in aserializer, the time spent evaluating default_timezone() once for eachof them can accumulate to quite a bit, which is just unused work in thecase where timezone is already specified on the field.
1 parentfa9d516 commitdba9493

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎rest_framework/fields.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ def enforce_timezone(self, value):
11791179
When `self.default_timezone` is `None`, always return naive datetimes.
11801180
When `self.default_timezone` is not `None`, always return aware datetimes.
11811181
"""
1182-
field_timezone=getattr(self,'timezone',self.default_timezone())
1182+
field_timezone=self.timezoneifhasattr(self,'timezone')elseself.default_timezone()
11831183

11841184
iffield_timezoneisnotNone:
11851185
iftimezone.is_aware(value):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp