Skip to content

Fix stale Stripe-Account header on directly-retrieved Event related objects - #1968

Merged
jar-stripe merged 2 commits into
masterfrom
jar/fix-event-context-scoping
Nov 7, 2026
Merged

jar-stripe merged 2 commits into
masterfrom
jar/fix-event-context-scoping

Conversation

@jar-stripe

@jar-stripe jar-stripe commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Why?

EventNotification scopes its client to the event's own stripe_context via StripeClient.with_stripe_context, which also clears stripe_account. A directly-retrieved Event (e.g. client.v2.core.events.retrieve(...)) has no equivalent, so fetch_related_object() sends the original request's Stripe-Context instead of the one returned with the event.

What?

  • Adds _APIRequestor.with_stripe_context(), which always replaces stripe_context and clears stripe_account
  • Rescopes a directly-retrieved v2 Event's requestor with it in _convert_to_stripe_object, the single construction path shared by retrieve, list, and EventNotification.fetch_event().

Test Plan

  • tests/test_api_requestor.py::test_with_stripe_context_clears_stripe_account: confirms the new helper clears a previously-set stripe_account even though _new_requestor_with_options can't.
  • tests/test_v2_event.py::test_direct_retrieve_related_object_retains_event_context: retrieves an Event directly with a client default account different from the event's own context, then asserts fetch_related_object() uses only the event's Stripe-Context with no Stripe-Account header. Reverting the fix makes both tests fail with the leaked Stripe-Account: acct_platform header.
  • Full suite (just test): 4375 passed, 7 skipped (pre-existing, unrelated).
  • just lint, just typecheck, just format-check: clean.

See Also

http://go/j/RUN_DEVSDK-3694 also covers java/ruby/php; this PR is the python slice.

Configuration

  • skip-changefile: This PR is not a user-facing change, so there's no changefile.

🤖 Generated with Claude Code

jar-stripe and others added 2 commits November 6, 2026 14:55
…bjects

A directly-retrieved v2 Event keeps the requestor of whatever account
fetched it, so Event.fetch_related_object() could send a stale
Stripe-Account header alongside the event's own Stripe-Context.
EventNotification already avoids this in its own construction via
StripeClient.with_stripe_context; give Event the same treatment where
it's deserialized in _convert_to_stripe_object.

Fixes RUN_DEVSDK-3694.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Committed-By-Agent: claude
Refactor handling of requestor context for v2 events.
@jar-stripe
jar-stripe marked this pull request as ready for review November 6, 2026 23:23
@jar-stripe
jar-stripe requested a review from a team as a code owner November 6, 2026 23:23
@jar-stripe
jar-stripe requested review from mnorth-stripe and removed request for a team November 6, 2026 23:23
@jar-stripe
jar-stripe enabled auto-merge (squash) November 7, 2026 00:14
@jar-stripe
jar-stripe merged commit e9f0e85 into master Nov 7, 2026
22 checks passed
@jar-stripe
jar-stripe deleted the jar/fix-event-context-scoping branch November 7, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants