Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't evaluate default_timezone unless needed (#8531)
If you set a custom timezone for a DateTimeField, the function self.default_timezone() is still called, since fallback params to getattr are still evaluated. This rewrites to use hasattr, so the fallback case is only executed if it will actually be used. If you render a lot of DateTimeFields in a serializer, the time spent evaluating default_timezone() once for each of them can accumulate to quite a bit, which is just unused work in the case where timezone is already specified on the field.
- Loading branch information