fix(google_genai): guard against None content.parts in _extract_response_text#5857
Closed
NIK-TIGER-BILL wants to merge 1 commit intogetsentry:masterfrom
Closed
fix(google_genai): guard against None content.parts in _extract_response_text#5857NIK-TIGER-BILL wants to merge 1 commit intogetsentry:masterfrom
NIK-TIGER-BILL wants to merge 1 commit intogetsentry:masterfrom
Conversation
…nse_text
When a Gemini candidate's content.parts attribute exists but is set to
None (e.g. interrupted generation or model returning an empty turn),
the previous hasattr() check passed but iterating over None raised:
TypeError: 'NoneType' object is not iterable
Replace the hasattr sentinel with getattr(..., None) which evaluates
falsy for both absent and None-valued attributes.
Fixes getsentry#5854
Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
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.
Description
When a Gemini API candidate's
content.partsattribute is present but set toNone(e.g. an interrupted generation or a model turn with no text), the existinghasattr(candidate.content, "parts")guard passed but the subsequentfor part in candidate.content.partsloop raised:The fix replaces the
hasattrsentinel withgetattr(..., None), which evaluates falsy for both absent and None-valued attributes, matching the pattern used elsewhere in the file (e.g. line 220).Changed files:
sentry_sdk/integrations/google_genai/utils.py— one-line guard fixtests/integrations/google_genai/test_google_genai.py— regression testIssues
Reminders
test_response_with_none_content_parts)