refactor: replace datetime.now and datetime.today with timezone.now#4211
Conversation
datetime.datetime.today() is equivalent to datetime.datetime.now(); both return a naive datetime with the current local time.
This is effectively the same, but is less likely to encourage accidental use of naive datetimes.
Codecov Report
@@ Coverage Diff @@
## feat/tzaware #4211 +/- ##
===============================================
Coverage ? 88.41%
===============================================
Files ? 294
Lines ? 39237
Branches ? 0
===============================================
Hits ? 34693
Misses ? 4544
Partials ? 0 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
|
Converting to draft while I check that it's still compatible with recent updates |
rjsparks
left a comment
There was a problem hiding this comment.
I reviewed this fairly quickly - I don't think there's much opportunity for simple errors in what the PR aims for, and we'll have plenty of time to check for subtle as we move to the next phase of this project.
| # remember the value so ietf.utils.mail.send_smtp() will use the same | ||
| ietf.utils.mail.SMTP_ADDR['port'] = base + offset | ||
| self.smtpd_driver = SMTPTestServerDriver((ietf.utils.mail.SMTP_ADDR['ip4'],ietf.utils.mail.SMTP_ADDR['port']),None) | ||
| ietf.utils.mail.SMTP_ADDR['port'] = base + offset |
There was a problem hiding this comment.
well, ok, but it makes reviewing a really big PR even longer...
There was a problem hiding this comment.
Not sure why these were changed - my editor is configured only to update whitespace on lines that changed in other ways.
Prepare for switching to
USE_TZ=Trueby globally replacingdatetime.datetime.now()withdjango.utils.timezone.now()through the project. Calls todatetime.datetime.today()have also been replaced. Despite the misleading name, this method is a synonym fordatetime.datetime.now()when the latter is used without an argument.Adds migrations to update model fields whose default value was set using
datetime.now. Two old migrations useddatetime.datetime.today()to find sessions in the future. After initially updating these to usetimezone.now(), I reverted the change because I think it makes sense to leave these as they were. Migrating back to that point without settingUSE_TZ=Falseis going to break timestamps anyway. If we really want to support that we could add a migration step to interrupt migrations and prompt the user to modifysettings.USE_TZat the appropriate time. I don't think that complexity is warranted, however.