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

patched GetCurrentTime to use correct timezone-aware datetime #19445

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

Conversation

b-d-e
Copy link

@b-d-e b-d-e commented Nov 28, 2024

Addresses #19161 by addressing the deprecation warning.

See python 3.12 release notes for motivating python change:

datetime: datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version. Instead, use timezone-aware objects to represent datetimes in UTC: respectively, call now() and fromtimestamp() with the tz parameter set to datetime.UTC. (Contributed by Paul Ganssle in gh-103857.)

Existing unit tests should handle these changes.

Without this, this warning appears when using protobuf:

.venv/lib/python3.12/site-packages/google/protobuf/internal/well_known_types.py:178: 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).
  self.FromDatetime(datetime.datetime.utcnow())

Copy link

google-cla bot commented Nov 28, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@b-d-e
Copy link
Author

b-d-e commented Nov 28, 2024

This won't work as is under Python 3.8.x, but that version has passed end-of-life support from Python - I don't know what the intended future support from protobuf is?

If desired, I can add a conditional check that changes the behaviour based on if version <3.9, using the old method if so.

@b-d-e b-d-e changed the title patched GetCurrentTime to use correct timezone aware datetime patched GetCurrentTime to use correct timezone-aware datetime Nov 28, 2024
@b-d-e b-d-e marked this pull request as ready for review November 28, 2024 15:02
@b-d-e b-d-e requested a review from a team as a code owner November 28, 2024 15:02
@b-d-e b-d-e requested review from anandolee and removed request for a team November 28, 2024 15:02
@shaod2 shaod2 added the python label Dec 2, 2024
@honglooker honglooker added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jan 7, 2025
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jan 7, 2025
@JasonLunn
Copy link
Contributor

@b-d-e - Can you take a look at the failing tests?

@b-d-e
Copy link
Author

b-d-e commented Feb 4, 2025

@JasonLunn - as far as I can see the test is failing with:

This pull request is from an unsafe fork and hasn't been approved to run tests.
A protobuf team member will need to review the PR and add the 'safe for tests' tag.

I can see the safe for tests tag was added a while back, but I can't see the output if any actions that were triggered by that? (sorry if I am missing something obvious here)

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

Successfully merging this pull request may close these issues.

4 participants