-
-
Notifications
You must be signed in to change notification settings - Fork 229
Preventing the Python 3.12's "Deprecated since version 3.12: Use datetime.now() with UTC instead." #914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…time.now() with UTC instead." For webrecorder#913
I made a mistake, forgot that WARCIO is also using naive datetimes. I'm working on a short term solution, please wait. |
I finally got my stuff together and remembered this one. I just realized that WARCIO was updated: (yeah, I'm a bit slow... 😬 ) I'm revising this code and comparing it with whatever I have something in (my custom) production at this moment - that code is working for months already, time more than enough to had bitten my back if I had made some serious mistake. |
7708930
to
1b78bb4
Compare
That's the history: With WARCIO 1.7.5 giving us the option for getting non naive This would be a problem on code touched by the previous commit, and so code reviewing the changes I found that So I changed these, adding
Doing a second code review, this time worrying about the consequences of the changes, I realized that these changes are not needed because the However, I had forgot that updating my branch would reflect automatically on this pull request, my bad. So I decided to rebase the branch back one commit, and ask first if you guys would prefer to have the code above changed due some internal compliance, or if whatever we have now is good to go. I'm marking this pull request as Ready for Review anyway - as I found no possible problem with WARCIO with or without getting naive --- edit: some typos fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR, and apologies for our taking a while to review it! I think there are two cases where we explicitly need to create naive datetimes still to avoid comparison issues.
@@ -164,13 +164,13 @@ def check_embargo(self, url, ts): | |||
# embargo if newser than | |||
newer = self.embargo.get('newer') | |||
if newer: | |||
actual = datetime.utcnow() - newer | |||
actual = datetime.now(timezone.utc) - newer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actual = datetime.now(timezone.utc) - newer | |
actual = datetime.now(timezone.utc).replace(tzinfo=None) - newer |
I think this is one of the few places where we do need to explicitly create a naive datetime or else an exception will be thrown due to comparison of naive and aware datetimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newer
is a relativedelta, not a datetime.
return access if actual < dt else None | ||
|
||
# embargo if older than | ||
older = self.embargo.get('older') | ||
if older: | ||
actual = datetime.utcnow() - older | ||
actual = datetime.now(timezone.utc) - older |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actual = datetime.now(timezone.utc) - older | |
actual = datetime.now(timezone.utc).replace(tzinfo=None) - newer |
Same as above.
Description
See #913
Types of changes
Checklist: