fix(openai): Attach response model with streamed Completions API #5557
1 issue
find-bugs: Found 1 issue (1 medium)
Medium
Unprotected attribute access to x.model may raise exception and break iteration - `sentry_sdk/integrations/openai.py:615`
The new code span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.model) directly accesses x.model without checking if the attribute exists, and it's placed OUTSIDE the capture_internal_exceptions() block. If x.model is missing or raises an exception (e.g., with API changes or non-standard responses), this will propagate to user code and break their stream iteration. This is inconsistent with the existing pattern at line 472 which uses hasattr(response, "model") before access, and with the responses API handler at line 758 which wraps similar access inside capture_internal_exceptions().
Duration: 2m 41s · Tokens: 963.9k in / 10.9k out · Cost: $1.59 (+extraction: $0.01)
Annotations
Check warning on line 615 in sentry_sdk/integrations/openai.py
github-actions / warden: find-bugs
Unprotected attribute access to x.model may raise exception and break iteration
The new code `span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.model)` directly accesses `x.model` without checking if the attribute exists, and it's placed OUTSIDE the `capture_internal_exceptions()` block. If `x.model` is missing or raises an exception (e.g., with API changes or non-standard responses), this will propagate to user code and break their stream iteration. This is inconsistent with the existing pattern at line 472 which uses `hasattr(response, "model")` before access, and with the responses API handler at line 758 which wraps similar access inside `capture_internal_exceptions()`.