Repository navigation
Fix stripe_account and stripe_context in Event#fetch_related_object - #2022
Merged
Merged
Conversation
A directly-retrieved Event#fetch_related_object fell back to the retrieving client's own stripe_account instead of the event's own context, because _request's combine_opts merge re-applied the Event's retained @opts. EventNotification already avoids this by scoping its @client to the notification's context at construction time; Event now does the equivalent by routing _request through a context-scoped, account-free requestor. Fixes RUN_DEVSDK-3694 (ruby portion). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Committed-By-Agent: claude
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Committed-By-Agent: claude
Event is generated from the OpenAPI spec, so the scoped_requestor/ _request override from the previous commit lived in a generated file with no durable home across regeneration. sdk-codegen (stripe/sdk-codegen#4349) now generates `Event < EventBase` instead of `Event < APIResource`; EventBase is a new hand-maintained class, autoloaded the same way as EventNotification, that carries the scoping logic verbatim. Regenerated via `just gen ruby --repo <this worktree>`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Committed-By-Agent: claude
jar-stripe
marked this pull request as ready for review
November 7, 2026 04:21
jar-stripe
requested review from
xavdid
and
a balanced review from Copilot
and removed request for
a team
November 7, 2026 04:21
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Related-object fetching discards retained API key and version overrides, risking authentication or schema mismatches, while missing EventBase RBI declarations leave Sorbet consumers with unresolved inheritance.
2 open issues
2 files not reviewed
rbi/stripe.rbi: File type not supportedrbi/stripe/resources/v2/core/event.rbi: File type not supported
What changed in this PR
This PR updates related-object requests from directly retrieved v2 events to use the event’s own context rather than the retrieving client’s account settings.
Changes:
- Introduces a shared
EventBasewith an event-scoped requestor and updates event inheritance. - Adds regression coverage for context propagation and removal of stale account headers.
- Updates type annotations and adds a patch changefile.
| File | Description |
|---|---|
test/stripe/v2_event_test.rb |
Tests routing headers on related-object fetches and subsequent requests. |
rbi/stripe/resources/v2/core/event.rbi |
Changes the event’s declared superclass to EventBase. |
rbi/stripe.rbi |
Updates event inheritance in the combined annotations. |
lib/stripe/resources/v2/core/event.rb |
Makes events inherit the shared request behavior. |
lib/stripe/resources/v2/core/event_base.rb |
Adds a cached, context-scoped requestor. |
lib/stripe/resources.rb |
Registers and loads EventBase. |
.hark/changes/2026-11-06_jar_fix-event-context-scoping.change.md |
Documents the context-scoping fix. |
Review effort: Balanced
…re EventBase RBI EventBase#_request skipped RequestOptions.combine_opts(@opts, req_opts) entirely, so a retained per-object api_key or stripe_version override (e.g. from events.retrieve(id, api_key: 'rk_restricted')) was silently dropped on fetch_related_object, falling back to the ambient requestor's default. Restores the merge, with @opts's own stripe_account/stripe_context forced to the safe values first so a stale account can't leak back in through it. Also ships a hand-maintained rbi/stripe/resources/v2/core/event_base.rbi, mirroring event_notification.rbi, since EventBase is referenced as Event's superclass in the generated RBI but was otherwise undeclared anywhere in the packaged gem. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Committed-By-Agent: claude
jar-stripe
enabled auto-merge (squash)
November 7, 2026 04:40
zacchua-stripe
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Why?
A directly-retrieved
Event(as opposed to anEventNotificationbuilt from a webhook) kept falling back to the retrieving client's ownstripe_accountinstead of the event's owncontextwhen fetching a related object, because_request'scombine_optsmerge re-applied theEvent's retained@opts.What?
Event#_requestto route through astripe_context-scoped,stripe_account-free requestor built once per event, mirroring howEventNotificationalready scopes its@clientat construction time.Event, callsfetch_related_object, and asserts only the event's ownStripe-Contextis sent on both that call and a subsequent call on the fetched object, with no staleStripe-Account.See Also
Configuration
skip-changefile: This PR is not a user-facing change, so there's no changefile.