api: Add auto_retry_rate_limits option to Client to handle 429 errors#908
Open
sohampanda000 wants to merge 1 commit intozulip:mainfrom
Open
api: Add auto_retry_rate_limits option to Client to handle 429 errors#908sohampanda000 wants to merge 1 commit intozulip:mainfrom
sohampanda000 wants to merge 1 commit intozulip:mainfrom
Conversation
Contributor
|
Thanks! Please go through our guide on submitting a pull request to learn how to present your proposed changes to Zulip, so that your work can be reviewed. |
d485afc to
6e58da8
Compare
Collaborator
Author
|
Alya, thank you for the pointer! I updated this PR to follow Zulip's commit discipline by rebasing everything into one commit. |
Collaborator
Author
|
@alya could you check this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My Pull Request (PR) adds the boolean
auto_retry_rate_limitsas a parameter in theClientclass in__init__.pyof the Python Zulip API.Fixes:
Python's API Library does not handle HTTP 429 (
RATE_LIMIT_HIT) errors automatically. If a client exceeds the message limit, Python will throw an error and forces users to manually implement a method to pause the thread and try again.To resolve this, the
__init__constructor of theClientclass has been given a new addition of an opt-in parameter initialized toFalseto keep existing behavior. This catches the429status code in this function:do_api_query().So, it is ensured that the client safely parses the
retry-aftervalue, pauses the sleep thread using thetime.sleep()function, and finally tries the message request again without failure.How changes were tested:
Continuous Pipeline (CI) Testing: I pushed the commit, via
git push, to trigger the GitHub Actions CI Suite. This commit sustains the code through standard API testing suits. Additionally, thezulintlinter checks Python formatting and that no client configurations have broke.Testing Verification: After verifying everything, I made sure of the
try/catchcode block for parsingretry-afterdefaults to 1 seconds only if the JSON (body or header) is unusual at all.Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following:
Refer to Issue #773 for further information.