fix(lib): guard parse_response against response.output=None#3460
Open
nicha16 wants to merge 1 commit into
Open
fix(lib): guard parse_response against response.output=None#3460nicha16 wants to merge 1 commit into
nicha16 wants to merge 1 commit into
Conversation
parse_response iterated response.output directly, raising
TypeError('NoneType' object is not iterable) when a completed Response
has output=None (incomplete/failed/reasoning-only responses, and some
proxy/aggregator backends). Because this fires inside the streaming
accumulator (accumulate_event -> parse_response), it crashes the whole
stream rather than surfacing as a handleable result.
Guard with (response.output or []). Adds a regression test that
reproduces the crash without the guard.
Fixes openai#3459
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 #3459
Problem
parse_responseinsrc/openai/lib/_parsing/_responses.pyiteratesresponse.outputwithout guarding againstNone:When a completed
Responsehasoutput=None, this raisesTypeError: 'NoneType' object is not iterable. Becauseparse_responseis invoked from the streaming accumulator (lib/streaming/responses/_responses.py::accumulate_event→parse_response), the exception crashes the entire stream rather than surfacing as a handleable result — and it originates deep in the SDK, so it isn't catchable as a normal API error.outputcan beNonefor incomplete / failed / reasoning-only responses, and via some proxy/aggregator backends.Fix
Guard the iteration:
A
None/absentoutputnow yields aParsedResponsewith an emptyoutputlist instead of crashing.Test
Adds
tests/lib/responses/test_parse_response_none_output.py, a focused regression test that callsparse_responsewith aResponsewhoseoutputisNone.Validated in isolation:
TypeError: 'NoneType' object is not iterableat_parsing/_responses.py(reproduces the bug).The change is one line plus a test; happy to adjust naming/placement to match your conventions.