Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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,
@codecov
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a47ead1) to head (7ce6952).

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 <[email protected]>
@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.

@Mariatta
Copy link
Member

@Kjeld-P still interested in updating your PR with unit tests as requested?

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.

3 participants