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

[master] Datetime utcnow #66902

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

marmarek
Copy link
Contributor

What does this PR do?

This removes some usage of deprecated datetime.datetime.utcnow() and replaces them with timezone-aware objects, while not changing the actual behavior.

What issues does this PR fix or reference?

Partial fix for #65604

This is complementary to #66042

Previous Behavior

Salt logs warnings like:

/usr/lib/python3.12/site-packages/salt/utils/jid.py:19: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

New Behavior

No warning.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices, including the
PR Guidelines.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@marmarek marmarek requested a review from a team as a code owner September 18, 2024 15:10
@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title Datetime utcnow [master] Datetime utcnow Sep 18, 2024
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have some pre-commit failures

@marmarek
Copy link
Contributor Author

Looks like you have some pre-commit failures

Fixed

@twangboy
Copy link
Contributor

Looks like the test failures are related to your changes in utils/pkg/rpm.py

dmurphy18
dmurphy18 previously approved these changes Sep 18, 2024
@marmarek
Copy link
Contributor Author

Looks like the test failures are related to your changes in utils/pkg/rpm.py

What test failures? For the current version I don't see any (there are either green, or pending)

@twangboy
Copy link
Contributor

The test suite tries 3 times... here is the 2nd run:
https://github.com/saltstack/salt/actions/runs/10925697063/attempts/2?pr=66902

@marmarek
Copy link
Contributor Author

Ah, I see, datetime.UTC alias is available only since Python 3.11. Fixed.

datetime.datetime.utcnow() is deprecated in Python 3.12, and it's
recommended to switch to timezone-aware objects, so do this. It also
simplifies local time handling, as .astimezone() method can be used
instead of calculating timezone_delta manually.

Part of saltstack#65604
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.

3 participants