Skip to content

Preserve Event's own context when fetching and mutating its related object - #2329

Open
jar-stripe wants to merge 3 commits into
masterfrom
jar/fix-event-context-scoping
Open

jar-stripe wants to merge 3 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.fetchRelatedObject() already deserializes the related object with a context-scoped client (client.withStripeContext(context)), but Event.fetchRelatedObject() deserialized with the unscoped getter it was originally fetched with. A later no-options mutation on the returned object could therefore pick up whatever default account/context the original client had, instead of the event's own context.

What?

  • adds withStripeContext(String) to StripeResponseGetter, with an implementation on LiveStripeResponseGetter that clones the getter's options with stripe_account cleared and stripe_context set, regardless of the concrete StripeResponseGetterOptions implementation backing it
  • changes Event.fetchRelatedObject() to fetch and deserialize the related object through a getter scoped to the event's own context, so any later no-options request on the returned object (e.g. a mutation) is scoped the same way
  • changes StripeClient.withStripeContext() to delegate to the new StripeResponseGetter.withStripeContext() instead of duplicating the options-cloning logic inline

See Also

http://go/j/RUN_DEVSDK-3688

Configuration

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

…bject

Event.fetchRelatedObject() used the response getter it was deserialized
with directly, so a later no-options mutation on the returned object
could pick up whatever default account/context the original client had,
instead of the event's own context. EventNotification already avoided
this by deserializing with a context-scoped client; give Event the same
treatment by adding withStripeContext() to StripeResponseGetter /
LiveStripeResponseGetter, and have StripeClient.withStripeContext()
delegate to it instead of duplicating the options-cloning logic.

Fixes RUN_DEVSDK-3694 (java).

Committed-By-Agent: claude
Removed redundant comments about the context scoping.
@jar-stripe
jar-stripe marked this pull request as ready for review November 7, 2026 04:11
@jar-stripe
jar-stripe requested a review from a team as a code owner November 7, 2026 04:11
@jar-stripe
jar-stripe requested review from mnorth-stripe and removed request for a team November 7, 2026 04:11
@jar-stripe
jar-stripe enabled auto-merge (squash) November 7, 2026 04:11

This branch has not been deployed

No deployments
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.

1 participant