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

Raise a RateLimitExceededException when a secondary rate limit is hit #2127

Conversation

william-richard
Copy link

I have been writing some new code that ended up hitting github's secondary rate limit,
and was confused why it was being returned as a generic GithubException instead of a RateLimitExceededException.

I dug into the code, figured out why, and put together this patch.

Let me know if there's anything I can do to improve it, especially with the replay data

I have been writing some new code that ended up hitting github's secondary rate limit,
and was confused why it was being returned as a generic `GithubException` instead of a `RateLimitExceededException`.

I dug into the code, figured out why, and put together this patch.

Let me know if there's anything I can do to improve it, especially with the replay data
@william-richard william-richard force-pushed the will-raise-RateLimitExceededException-when-a-secondary-rate-limit-is-hit branch from ff7b4d3 to 7bcafff Compare December 15, 2021 19:27
@william-richard william-richard changed the title Raise a RateLimitExceededException when a secondary rate limit is hit Raise a RateLimitExceededException when a secondary rate limit is hit Dec 15, 2021
@william-richard william-richard changed the title Raise a RateLimitExceededException when a secondary rate limit is hit Raise a RateLimitExceededException when a secondary rate limit is hit Dec 15, 2021
@william-richard william-richard changed the title Raise a RateLimitExceededException when a secondary rate limit is hit Raise a RateLimitExceededException when a secondary rate limit is hit Dec 15, 2021
@EnricoMi
Copy link
Collaborator

EnricoMi commented Jan 10, 2022

I have not seen your error before:

"You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later."

But I have seen these (EnricoMi/publish-unit-test-result-action#170, EnricoMi/publish-unit-test-result-action#150):

"You have exceeded a secondary rate limit. Please wait a few minutes before you try again."
"You have triggered an abuse detection mechanism. Please wait a few minutes before you try again."

which are already caught by PyGithub due to the .endswith("please wait a few minutes before you try again.").

Your message does not match as it misses that string ending. Maybe, besides adding the string starting as you suggest, it is also worth adding the string ending of your message as well to catch other errors that haven't been seen / reported yet and GitHub is likely to come up with: .endswith("please retry your request again later.").

@@ -424,6 +424,9 @@ def __createException(self, status, headers, output):
or output.get("message")
.lower()
.endswith("please wait a few minutes before you try again.")
or output.get("message")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it is more intuitive to move that startswith up to the first startswith to collect startswith conditions and endswith conditions.

@@ -133,6 +133,17 @@ def exceed():

self.assertRaises(github.RateLimitExceededException, exceed)

def testSecondaryRateLimitExceeded(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are other messages that indicate secondary rate limit, worth testing them as well? #2127 (comment)

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@codecov-commenter
Copy link

Codecov Report

Base: 98.90% // Head: 98.77% // Decreases project coverage by -0.13% ⚠️

Coverage data is based on head (7bcafff) compared to base (5c290c9).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2127      +/-   ##
==========================================
- Coverage   98.90%   98.77%   -0.13%     
==========================================
  Files         108      117       +9     
  Lines       11131    11674     +543     
==========================================
+ Hits        11009    11531     +522     
- Misses        122      143      +21     
Impacted Files Coverage Δ
github/Requester.py 97.43% <100.00%> (-0.72%) ⬇️
github/WorkflowRun.py 98.00% <0.00%> (-2.00%) ⬇️
github/PullRequest.py 97.48% <0.00%> (-0.79%) ⬇️
github/InstallationAuthorization.py 92.10% <0.00%> (-0.21%) ⬇️
github/Repository.py 97.20% <0.00%> (-0.11%) ⬇️
github/Consts.py 100.00% <0.00%> (ø)
github/__init__.py 100.00% <0.00%> (ø)
github/CodeScanAlertInstance.py 100.00% <0.00%> (ø)
github/CodeScanTool.py 100.00% <0.00%> (ø)
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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

@EnricoMi EnricoMi closed this Jun 19, 2023
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.

None yet

3 participants