Skip to content
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

Resolve Python 3.12 .utcnow() DeprecationWarning #3239

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

kurtmckee
Copy link

@kurtmckee kurtmckee commented Aug 16, 2024

This PR resolves the Python 3.12 DeprecationWarning thrown when botocore calls datetime.datetime.utcnow().

@nateprewitt, this PR differs from other attempts posted to this repo by ensuring datetime instances are still timezone-unaware:

import datetime

# Current form: timezone-unaware, raises DeprecationWarnings in >=py3.12
datetime.datetime.utcnow()

# Common transformation -- makes the instance timezone-aware!
datetime.datetime.now(datetime.timezone.utc)

# This PR's approach -- ensures instance is still timezone-unaware
datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)

I ran this through CI in my own repo and it passes cleanly.

Fixes boto/boto3#3889.

@StevenMapes
Copy link

StevenMapes commented Sep 26, 2024

It would be good to get this merged soon, it's been something tracked over on the boto3 issues for almost a year

@kurtmckee
Copy link
Author

kurtmckee commented Sep 26, 2024

@SamRemis, @nateprewitt, @jonathan343 -- Friendly request to review this PR when you have an opportunity.

@aleyan
Copy link

aleyan commented Sep 26, 2024

@kurtmckee thank you so much for looking into this. This DeprecationWarning transitively via boto has forced my terminal to scrolls 1000s of kilometers over the past year.

Since this PR keeps the timezone-less functionality, consider putting datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) into a utility method that will make it harder to get it wrong and make it easier to find all the places where timezone-less datetimes will need to be remediated. naive_utcnow() suggested as the name based on the blogpost about this deprecation.

@glaubitz
Copy link

There are now at least four PRs trying to adress this issue and none of these have been merged.

Could any of the PRs #3089, #3093, #3145 or #3239 be merged to address this warning before it becomes are hard error?

@kurtmckee
Copy link
Author

ALL -- Please do not add junk comments.

They contribute nothing and pollute actual discussion if and when it happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boto3 UTC DeprecationWarnings
4 participants