-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
In src/openai/_streaming.py lines 169-181, there's unreachable dead code.
The outer condition requires sse.event.startswith("thread."), but the inner condition checks sse.event == "error". Since "error" does not start with "thread.", this check can never be true.
This appears to be a regression from commit abc25966 ("fix(streaming): correct indentation"). The original code had the error check in the else branch, but after refactors it was incorrectly moved inside the thread. branch.
Reference: https://github.com/openai/openai-python/blob/main/src/openai/_streaming.py#L169-L181
To Reproduce
- Open
src/openai/_streaming.py - Go to line 167-181
- Observe that
sse.event == "error"is insideif sse.event.startswith("thread.")block - This condition is logically impossible to satisfy
Code snippets
# Line 167-168: outer condition
if sse.event and sse.event.startswith("thread."):
data = sse.json()
# Line 170: inner condition - ALWAYS False
# "error" does not start with "thread.", so this is unreachable
if sse.event == "error" and is_mapping(data) and data.get("error"):
raise APIError(...) # Dead code!OS
Windows
Python version
Python v3.11.4
Library version
openai v2.11.0
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working