GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(anthropic): Preserve cached `_iterator` property by alexander-alderman-webb · Pull Request #8163 · getsentry/sentry-python

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Description

See anthropics/anthropic-sdk-python@abd6424.
Since _iterator was changed from a member initialized in __init__ to a cached property, the SDK can and should use a global patch so we don't destroy the laziness of accessing the cached property.

A global patch is also more maintainable because we don't have to worry about double patching, etc ...

I've changed the generic parameter for Stream and AsyncStream to Any, since users can technically provide a custom parser.

Also fixed the following mypy errors when upgrading anthropic in uv.lock:

sentry_sdk/integrations/anthropic.py:786: error: Property "_iterator" defined in "Stream" is read-only  [misc]
sentry_sdk/integrations/anthropic.py:884: error: Property "_iterator" defined in "AsyncStream" is read-only  [misc]

Issues

Closes #8166

Reminders

  • Please add tests to validate your changes, and lint your code using uv run ruff.
  • Add GH Issue ID & Linear ID (if applicable)
  • PR title should use conventional commit style (feat:, fix:, ref:, meta:)
  • For external contributors: CONTRIBUTING.md, Sentry SDK development docs, Discord community

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-alderman-webb
fix(anthropic): Preserve cached _iterator property
a011f64
@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/anthropic/preserve-cached-property branch from 8e1712b to 054e95c Compare October 30, 2026 08:47
@alexander-alderman-webb
update anthropic in typing lockfile
fe7b26b
@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/anthropic/preserve-cached-property branch 2 times, most recently from 6812235 to a215e50 Compare October 30, 2026 09:04
@github-actions

github-actions Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 136864 passed | ⏭️ 7456 skipped | Total: 144320 | Pass Rate: 94.83% | Execution Time: 450m 47s

All tests are passing successfully.

✅ Patch coverage is 93.33% (28 of 30 changed executable lines covered; target 80%).
Project statement coverage is 90.32%.

Changed files with executable lines (1)
File Patch coverage Changed executable lines
sentry_sdk/integrations/anthropic.py 93.33% 28/30 covered; missed: 279, 280

Generated by Coverage Action

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review October 30, 2026 10:18
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner October 30, 2026 10:18
cursor[bot]
cursor Bot reviewed Oct 30, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a215e50. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread sentry_sdk/integrations/anthropic.py
result._iterator = _wrap_synchronous_message_iterator( # type: ignore[misc]
cast("_PatchedRawMessageStream", result),
result._iterator,
)

@cursor cursor Bot Oct 30, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version gate skips iterator wrapping

High Severity

The global _iterator patch is applied only when _iterator is a functools.cached_property, but per-instance wrapping is skipped for every Anthropic version >= 1.14. Those two checks are not complementary, so a 1.14+ install whose _iterator is still an eager attribute (or a different descriptor than functools.cached_property) gets neither wrap. Streaming spans then miss accumulated output data, and if the caller never calls close(), the span never finishes.

Additional Locations (2)
  • sentry_sdk/integrations/anthropic.py#L931-L940
  • sentry_sdk/integrations/anthropic.py#L284-L316
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a215e50. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@alexander-alderman-webb alexander-alderman-webb Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they ever change it from being a cached property we want to degrade gracefully (and that's more important than finishing the span).
I know this looks weird but I use the version gate for the old behavior because we know that works without checking the type of _iterator and check that _iterator is a cached property otherwise to ensure forwards compatibility.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-alderman-webb
improve types
8606111
@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/anthropic/preserve-cached-property branch from a215e50 to 8606111 Compare November 3, 2026 09:06
sentrivana
sentrivana approved these changes Nov 3, 2026
View reviewed changes
alexander-alderman-webb added 5 commits November 3, 2026 16:26
@alexander-alderman-webb
Content was widened to a type that's JSON compatible or contains unse…
7e078a0
…rializable Image instances. See typesafe-ai/typesafe-sdk-python@f36e685. Record inline messages as their reference and do not raise on unserializable input.
@alexander-alderman-webb
merge master
aa9f45d
@alexander-alderman-webb
Merge branch 'webb/anthropic/preserve-cached-property' of github.com:…
96d4b46
…getsentry/sentry-python into webb/anthropic/preserve-cached-property
@alexander-alderman-webb
make version var private
1757172
@alexander-alderman-webb
merge master again
1eadca0
@alexander-alderman-webb
alexander-alderman-webb enabled auto-merge (squash) November 3, 2026 16:43
@alexander-alderman-webb
alexander-alderman-webb merged commit 648a576 into master Nov 3, 2026
172 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb
alexander-alderman-webb deleted the webb/anthropic/preserve-cached-property branch November 3, 2026 16:45
This was referenced Nov 4, 2026
publish: getsentry/[email protected] getsentry/publish#10182
Closed
publish: getsentry/[email protected] getsentry/publish#10240
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@sentrivana sentrivana sentrivana approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Preserve cached _iterator in anthropic

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@alexander-alderman-webb @sentrivana
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.