ref(anthropic): Skip accumulation logic for unexpected types in streamed response #5564
1 issue
find-bugs: Found 1 issue (1 high)
High
NameError when Raw* types fail to import but are still referenced in isinstance checks - `sentry_sdk/integrations/anthropic.py:43-55`
When the RawMessageStartEvent, RawMessageDeltaEvent, etc. imports fail (line 54-55), message_types_have_raw_prefix is set to True, but the Raw* type names remain undefined. However, when message_types_have_raw_prefix is True, the code path in new_iterator() (lines 436-447) and new_iterator_async() (lines 500-512) evaluates isinstance(event, (RawMessageStartEvent, ...)), causing a NameError at runtime.
Also found at:
sentry_sdk/integrations/anthropic.py:435-447sentry_sdk/integrations/anthropic.py:500-523
Duration: 2m · Tokens: 98.7k in / 5.3k out · Cost: $0.42 (+extraction: $0.01, +merge: $0.00)
Annotations
Check failure on line 55 in sentry_sdk/integrations/anthropic.py
github-actions / warden: find-bugs
NameError when Raw* types fail to import but are still referenced in isinstance checks
When the `RawMessageStartEvent`, `RawMessageDeltaEvent`, etc. imports fail (line 54-55), `message_types_have_raw_prefix` is set to `True`, but the `Raw*` type names remain undefined. However, when `message_types_have_raw_prefix` is `True`, the code path in `new_iterator()` (lines 436-447) and `new_iterator_async()` (lines 500-512) evaluates `isinstance(event, (RawMessageStartEvent, ...))`, causing a `NameError` at runtime.
Check failure on line 447 in sentry_sdk/integrations/anthropic.py
github-actions / warden: find-bugs
[ENY-2R6] NameError when Raw* types fail to import but are still referenced in isinstance checks (additional location)
When the `RawMessageStartEvent`, `RawMessageDeltaEvent`, etc. imports fail (line 54-55), `message_types_have_raw_prefix` is set to `True`, but the `Raw*` type names remain undefined. However, when `message_types_have_raw_prefix` is `True`, the code path in `new_iterator()` (lines 436-447) and `new_iterator_async()` (lines 500-512) evaluates `isinstance(event, (RawMessageStartEvent, ...))`, causing a `NameError` at runtime.
Check failure on line 523 in sentry_sdk/integrations/anthropic.py
github-actions / warden: find-bugs
[ENY-2R6] NameError when Raw* types fail to import but are still referenced in isinstance checks (additional location)
When the `RawMessageStartEvent`, `RawMessageDeltaEvent`, etc. imports fail (line 54-55), `message_types_have_raw_prefix` is set to `True`, but the `Raw*` type names remain undefined. However, when `message_types_have_raw_prefix` is `True`, the code path in `new_iterator()` (lines 436-447) and `new_iterator_async()` (lines 500-512) evaluates `isinstance(event, (RawMessageStartEvent, ...))`, causing a `NameError` at runtime.