-
Notifications
You must be signed in to change notification settings - Fork 407
Fix #775: Wrong rate limit returned for search
#776
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
Fix #775: Wrong rate limit returned for search
#776
Conversation
This change adds a field which indicates against what rate limit API calls from an object are counted against. GitHub API v3 enforces different rate limits [1] for subsets of API calls. The `search` API has custom rate limts.[2] `GitHubCore` has a property `remaining_ratelimit` which requests rate limit information from endpoint `GET /rate_limit` [3] and caches the number in `GitHubCore._remaining`. The API call returns information about all rate limits but previously `GitHubCore.remaining_ratelimit` only exposed the one for the `core` resources. With this change the resource still defaults to `core` but objects sending search request change this to `search`. [1]: https://developer.github.com/v3/#rate-limiting [2]: https://developer.github.com/v3/search/#rate-limit [3]: https://developer.github.com/v3/rate_limit/
github3/models.py
Outdated
@@ -42,6 +42,7 @@ def __init__(self, json, session=None): | |||
|
|||
# set a sane default | |||
self._github_url = 'https://api.github.com' | |||
self._ratelimit_resource = 'core' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a class attribute, e.g.,
class GitHubCore(...):
_ratelimit_resource = 'core'
Then we could have
class GitHubSearchBase(GitHubCore):
"""..."""
_ratelimit_resource = 'search'
without having to override __init__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite sure the changes to search result classes (in Are there any other methods that I would need to take into account? Is I see it at the moment, I'd rather remove the entire |
I don't think so.
I guess the question for you and @omgjlk is: How often do you use the |
Why would you remove the entire method? For search result classes it could/should still return the |
Requests sent from search result classes do not actually count against the 'search' rate limit. Only search requests (i.e. by a `SearchIterator` incur 'search' rate limit.
We call |
Is there anything you would want to like improved in order to to get this merged? |
Thanks for iterating on this with us @justfortherec! |
This pull request is an attempt to fix issue #775