salt
salt copied to clipboard
[master] Fix datetime.datetime.utcnow() deprecated in Python 3.12
What does this PR do?
This changes all instances of datetime.utcnow() to datetime.now(tz=timezone.utc).
What issues does this PR fix or reference?
Fixes: #65604
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
- [ ] Docs
- [ ] Changelog - https://docs.saltproject.io/en/master/topics/development/changelog.html
- [ ] Tests written/updated
Commits signed with GPG?
No
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:
- Community Wiki
- Salt’s Contributor Guide
- Join our Community Slack
- IRC on LiberaChat
- Salt Project YouTube channel
- Salt Project Twitch channel
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!
I think this might be not backward compatible, because utcnow() returns a naive datetime, and now(tz=datetime.UTC) returns a timezone-aware one.
To create a naive datetime
from datetime import datetime, UTC
datetime.now(UTC).replace(tzinfo=None)
I think this might be not backward compatible, because
utcnow()returns a naive datetime, andnow(tz=datetime.UTC)returns a timezone-aware one.
That's the point of this deprecation warning, no? To stop using non-timezone-aware objects.