Repository navigation
api: Fail fast on UNAUTHORIZED and BAD_REQUEST in call_on_each_event. - #937
Open
SPY-Github22 wants to merge 1 commit into
Open
SPY-Github22 wants to merge 1 commit into
SPY-Github22 wants to merge 1 commit into
Conversation
When call_on_each_event encounters errors during registration or event fetching, it retried indefinitely even for unrecoverable client errors such as invalid/expired API keys (UNAUTHORIZED) or malformed query arguments (BAD_REQUEST). This led to silent infinite retry loops. Fail fast by immediately raising ZulipError when the server returns code UNAUTHORIZED or BAD_REQUEST in both do_register and the main event loop. Fixes zulip#783.
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.
Fixes #783.
Problem
Client.call_on_each_eventaggressively retried on errors encountered during both initial queue registration (do_register) and long-polling event fetching (get_events). For unrecoverable client configuration errors—such as invalid/expired API keys (code="UNAUTHORIZED") or invalid narrow parameters (code="BAD_REQUEST")—this caused the client to silently loop forever without informing the caller of the error.Solution
do_register(), check ifres.get("code") in ("UNAUTHORIZED", "BAD_REQUEST")and immediatelyraise ZulipError(f"{code}: {msg}".strip(": ")).elif code in ("UNAUTHORIZED", "BAD_REQUEST"):directly withinif "error" in res["result"]:(addressing earlier maintainer feedback from @timabbott in api: Fail fast on UNAUTHORIZED/BAD_REQUEST in call_on_each_event. (Fixes #783) #882).BAD_EVENT_QUEUE_ID, HTTP errors from server restarts, network disconnects).zulip/tests/test_call_on_each_event.pycovering:UNAUTHORIZEDandBAD_REQUEST).msgis omitted or empty.UNAUTHORIZEDandBAD_REQUEST).BAD_EVENT_QUEUE_IDerror.call_on_each_messagealso fails fast as expected.