fix: handle non-list response_stream in HttpResponse.json property #1903
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.
Description
When using the aiohttp backend and Google API returns a 500 Internal Server Error, the
HttpResponse.jsonproperty raisesTypeError: 'ClientResponse' object is not subscriptableinstead of allowing proper error handling.This happens because
response_streamcan be anaiohttp.ClientResponseobject (not a list) when an error occurs, and the code attempts to accessresponse_stream[0]without checking the type first.Root Cause
In
google/genai/_api_client.py, thejsonproperty assumesresponse_streamis always a list:The Fix
Add a type check before attempting list access:
Impact
Without this fix:
ServerError: 500 INTERNALis masked byTypeErrorWith this fix:
ServerErroris raised correctlyTesting
This fix has been validated in production for 24+ hours:
Before the fix (Dec 30, 2025 until 18:40 UTC-3):
TypeError: 'ClientResponse' object is not subscriptableerrorsAfter the fix (Dec 30, 2025 19:00 UTC-3 - Dec 31, 2025 16:00 UTC-3):
TypeError: 'ClientResponse' object is not subscriptableerrorsRelated Issue
Fixes #1897