Resolve Python 3.12 `.utcnow()` `DeprecationWarning`
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.
It would be good to get this merged soon, it's been something tracked over on the boto3 issues for almost a year
@SamRemis, @nateprewitt, @jonathan343 -- Friendly request to review this PR when you have an opportunity.
@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.
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?
ALL -- Please do not add junk comments.
They contribute nothing and pollute actual discussion if and when it happens.
@nateprewitt @SamRemis Hello! Please review this PR when you can.
It resolves Python 3.12 utcnow DeprecationWarnings without introducing serialization problems caused by timezone-aware datetime instances.
Thanks @kurtmckee! We're aware of the PR and are looking to have a more comprehensive set of changes that build on this PR in the near future. This change will need to span several projects so it's taken a bit longer to allocate time for the work/review. We'll let you know when we're closer to a release.
You're welcome! :partying_face: