Skip to content

Commit e1c5af7

Browse files
fix: replace deprecated utcfromtimestamp in google-auth-oauthlib (#16732)
This PR replaces the usage of the deprecated `datetime.datetime.utcfromtimestamp` in the `google-auth-oauthlib` package and testdata. Using `datetime.datetime.fromtimestamp(session.token["expires_at"], datetime.timezone.utc).replace(tzinfo=None)` avoids the deprecation warning in Python 3.12 while preserving backwards compatibility by returning a naive datetime object. Fixes #15433 --- *PR created automatically by Jules for task [232508796818525143](https://jules.google.com/task/232508796818525143) started by @chalmerlowe* Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: chalmerlowe <7291104+chalmerlowe@users.noreply.github.com>
1 parent a1417ae commit e1c5af7

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

  • packages
    • gcp-sphinx-docfx-yaml/tests/testdata/auth/google_auth_oauthlib
    • google-auth-oauthlib/google_auth_oauthlib

packages/gcp-sphinx-docfx-yaml/tests/testdata/auth/google_auth_oauthlib/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,7 @@ def credentials_from_session(session, client_config=None):
147147
scopes=session.scope,
148148
granted_scopes=session.token.get("scope"),
149149
)
150-
credentials.expiry = datetime.datetime.utcfromtimestamp(session.token["expires_at"])
150+
credentials.expiry = datetime.datetime.fromtimestamp(
151+
session.token["expires_at"], datetime.timezone.utc
152+
).replace(tzinfo=None)
151153
return credentials

packages/google-auth-oauthlib/google_auth_oauthlib/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,7 @@ def credentials_from_session(session, client_config=None):
147147
scopes=session.scope,
148148
granted_scopes=session.token.get("scope"),
149149
)
150-
credentials.expiry = datetime.datetime.utcfromtimestamp(session.token["expires_at"])
150+
credentials.expiry = datetime.datetime.fromtimestamp(
151+
session.token["expires_at"], datetime.timezone.utc
152+
).replace(tzinfo=None)
151153
return credentials

0 commit comments

Comments
 (0)