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

Check whether the return value from RateLimit.from_http() is None #207

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Kjeld-P
Copy link

@Kjeld-P Kjeld-P commented Dec 25, 2023

In handling error-responses from the server the code checks if it's possible to create a rate limit object from the headers through RateLimit.from_http(headers). This function returns an object if rate limit info was found, and None otherwise.

The next line of code wants to check if this value was not none, but does not do so explicitly: if rate_limit. This causes python to evaluate it as a boolean and call RateLimit.__bool__. This will only return True if self.remaining > 0, which would not be the case if the rate-limit was indeed exceeded.

The proposed fix simply explicitly checks if the returned RateLimit object is not None.

Check if rate_limit is a valid object rather than evaluating it as a bool when deciding whether to raise a RateLimit exception or not,
gidgethub/sansio.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7f8cec4) 100.00% compared to head (bb6a1ed) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #207   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          471       471           
  Branches        87        87           
=========================================
  Hits           471       471           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brettcannon brettcannon changed the title Fix rate-limit bug Check whether the return value from RateLimit.from_http() is None Jan 4, 2024
@brettcannon
Copy link
Collaborator

You're right about the bug! Slight code tweak to your PR and it's failing linting.

Co-authored-by: Brett Cannon <brett@python.org>
@Kjeld-P
Copy link
Author

Kjeld-P commented Jan 5, 2024

@brettcannon Thanks, added the suggestion!

@brettcannon brettcannon self-requested a review January 12, 2024 18:28
Copy link
Collaborator

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

I just realized there isn't a test for this. 😅 Could you add one?

@Mariatta
Copy link
Member

We also need the changelog entry for this bug fix.

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