salt icon indicating copy to clipboard operation
salt copied to clipboard

[master] Fix datetime.datetime.utcnow() deprecated in Python 3.12

Open chloekaii opened this issue 1 year ago • 4 comments

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.

chloekaii avatar Feb 11 '24 22:02 chloekaii

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:

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!

welcome[bot] avatar Feb 11 '24 22:02 welcome[bot]

I think this might be not backward compatible, because utcnow() returns a naive datetime, and now(tz=datetime.UTC) returns a timezone-aware one.

max-arnold avatar Feb 12 '24 06:02 max-arnold

To create a naive datetime

from datetime import datetime, UTC
datetime.now(UTC).replace(tzinfo=None)

twangboy avatar Feb 12 '24 16:02 twangboy

I think this might be not backward compatible, because utcnow() returns a naive datetime, and now(tz=datetime.UTC) returns a timezone-aware one.

That's the point of this deprecation warning, no? To stop using non-timezone-aware objects.

marmarek avatar Aug 15 '24 12:08 marmarek