fix(relay): return None on non-object media upload response - #72933
Open
wuisabel-gif wants to merge 1 commit into
Open
fix(relay): return None on non-object media upload response#72933wuisabel-gif wants to merge 1 commit into
wuisabel-gif wants to merge 1 commit into
Conversation
RelayMediaClient.upload() documents 'returns None on any failure', and its
except catches (URLError, ValueError, OSError). But a valid-JSON non-object
response (null, [], a string) reached body.get('id') and raised AttributeError,
which is outside that tuple — so it escaped upload() and broke the best-effort
fallback the send_* lanes rely on.
Guard the parsed body with isinstance(body, dict) before .get. Add a
parametrized test (null/[]/"ok"/42) proving upload() returns None instead of
raising.
Contributor
|
Thanks for the focused regression fix. The premise is confirmed on current main: The proposed guard preserves that contract, and the parametrized cases cover the relevant valid-JSON non-object values. Current main retains the PR diff's production-file preimage, so this is mechanically salvageable. Automated hermes-sweeper review. |
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.
What does this PR do?
RelayMediaClient.upload()(gateway/relay/media.py) documents that it "returns None on any failure (callers fall back to their pre-media behaviour, media delivery is best-effort by design)." Itsexceptclause catches(urllib.error.URLError, ValueError, OSError).But after a successful HTTP response it does
body = json.loads(...)and thenbody.get("id"). If the connector returns a valid JSON value that is not an object (null,[], a string, a number),json.loadssucceeds andbody.get("id")raisesAttributeError, which is not in the caught tuple. So it escapesupload(), propagates through_send_media()and thesend_image_file/send_voice/send_video/send_documentsenders, and bypasses the best-effort fallback those lanes rely on ("never a regression when the connector predates the op").This guards the parsed body with
isinstance(body, dict)before.get, so a non-object response degrades toNonelike every other failure.Related Issue
No open issue. Found by reading the Phase 2 media code (PR #71363, commit 689b51b).
Type of Change
Changes Made
gateway/relay/media.py: inupload()'s_post(), returnNonewhen the parsed JSON body is not a dict, before calling.get("id").tests/gateway/relay/test_relay_media.py: add a parametrized test (null,[],"ok",42) assertingupload()returnsNoneinstead of raising.How to Test
isinstanceguard makes the 4 new cases fail withAttributeError: '...' object has no attribute 'get', confirming the test catches the bug.Checklist