ref(anthropic): Skip accumulation logic for unexpected types in streamed response #5564
1 issue
code-review: Found 1 issue (1 high)
High
Inverted boolean flag causes incorrect event type filtering - `sentry_sdk/integrations/anthropic.py:42-54`
The message_types_have_raw_prefix flag is set incorrectly: it starts as False and is set to True only when the RawMessage*Event imports fail. This is backwards - if the Raw* types can be imported, the SDK has the raw prefix (flag should be True). If imports fail, it means there's no raw prefix (flag should be False). This causes the streaming event type filtering logic (lines 434-459, 499-524) to behave incorrectly, potentially skipping data collection for valid events or attempting to use RawMessage*Event types that weren't successfully imported.
Also found at:
sentry_sdk/integrations/anthropic.py:434-457sentry_sdk/integrations/anthropic.py:499-522
Duration: 1m 52s · Tokens: 98.3k in / 4.8k out · Cost: $0.37 (+extraction: $0.01, +merge: $0.00)
Annotations
Check failure on line 54 in sentry_sdk/integrations/anthropic.py
github-actions / warden: code-review
Inverted boolean flag causes incorrect event type filtering
The `message_types_have_raw_prefix` flag is set incorrectly: it starts as `False` and is set to `True` only when the `RawMessage*Event` imports fail. This is backwards - if the `Raw*` types can be imported, the SDK has the raw prefix (flag should be `True`). If imports fail, it means there's no raw prefix (flag should be `False`). This causes the streaming event type filtering logic (lines 434-459, 499-524) to behave incorrectly, potentially skipping data collection for valid events or attempting to use `RawMessage*Event` types that weren't successfully imported.
Check failure on line 457 in sentry_sdk/integrations/anthropic.py
github-actions / warden: code-review
[B3A-766] Inverted boolean flag causes incorrect event type filtering (additional location)
The `message_types_have_raw_prefix` flag is set incorrectly: it starts as `False` and is set to `True` only when the `RawMessage*Event` imports fail. This is backwards - if the `Raw*` types can be imported, the SDK has the raw prefix (flag should be `True`). If imports fail, it means there's no raw prefix (flag should be `False`). This causes the streaming event type filtering logic (lines 434-459, 499-524) to behave incorrectly, potentially skipping data collection for valid events or attempting to use `RawMessage*Event` types that weren't successfully imported.
Check failure on line 522 in sentry_sdk/integrations/anthropic.py
github-actions / warden: code-review
[B3A-766] Inverted boolean flag causes incorrect event type filtering (additional location)
The `message_types_have_raw_prefix` flag is set incorrectly: it starts as `False` and is set to `True` only when the `RawMessage*Event` imports fail. This is backwards - if the `Raw*` types can be imported, the SDK has the raw prefix (flag should be `True`). If imports fail, it means there's no raw prefix (flag should be `False`). This causes the streaming event type filtering logic (lines 434-459, 499-524) to behave incorrectly, potentially skipping data collection for valid events or attempting to use `RawMessage*Event` types that weren't successfully imported.