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

Test and fix UTC issue with AppInstallationAuth #2561

Merged
merged 2 commits into from Jun 22, 2023

Conversation

EnricoMi
Copy link
Collaborator

Fixes #2560.

@EnricoMi EnricoMi added this to the Version 1.59.0 milestone Jun 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jun 20, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@d514222). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head b380f3c differs from pull request most recent head 5a700eb. Consider uploading reports for the commit 5a700eb to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2561   +/-   ##
=======================================
  Coverage        ?   98.35%           
=======================================
  Files           ?      131           
  Lines           ?    13140           
  Branches        ?        0           
=======================================
  Hits            ?    12924           
  Misses          ?      216           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@EnricoMi EnricoMi force-pushed the app-installation-auth-utc-fix branch from b380f3c to ca84755 Compare June 21, 2023 09:14
Copy link

@antoineKorbit antoineKorbit left a comment

Choose a reason for hiding this comment

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

I manually reproduce the code I show in the issue #2560, and it works fine by now. I'm able to do multiple query with the same github rest client as it's shown in the unit test.

Thanks for the quick fix.

@EnricoMi
Copy link
Collaborator Author

@antoineKorbit thanks for testing!

Copy link
Collaborator

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

Confused about the proposed change

@@ -307,7 +307,8 @@ def _is_expired(self) -> bool:
self.__installation_authorization.expires_at
- TOKEN_REFRESH_THRESHOLD_TIMEDELTA
)
return token_expires_at < datetime.now(timezone.utc)
# to be fixed by https://github.com/PyGithub/PyGithub/pull/1831
return token_expires_at < datetime.now(timezone.utc).replace(tzinfo=None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I'm confused. Why are you creating a date with the UTC timezone, then removing the timezone information?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need the UTC timestamp here (without timezone information), not the local time (without timezone information). Otherwise under- or overshoot the expiry by the local timezone offset hours.

The token_expires_at is a UTC timestamp without timezone information, so we cannot compare it with a timestamp that has timezone information.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand now, thanks!

Copy link
Collaborator

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

LGTM!

@EnricoMi EnricoMi force-pushed the app-installation-auth-utc-fix branch from ca84755 to 5a700eb Compare June 22, 2023 14:12
@EnricoMi EnricoMi merged commit ff3b80f into PyGithub:main Jun 22, 2023
10 checks passed
@EnricoMi EnricoMi deleted the app-installation-auth-utc-fix branch June 22, 2023 14:15
@EnricoMi
Copy link
Collaborator Author

@JLLeitschuh thanks!

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.

Checking github.Auth.AppInstallationAuth expiry raises timezone-related error
4 participants