From a3a8a7b5024425075c218480f4364b09c0fe1b31 Mon Sep 17 00:00:00 2001 From: Zachary Chua Date: Wed, 16 Sep 2026 11:54:04 -0700 Subject: [PATCH 1/2] Fix event handler account scoping Committed-By-Agent: codex Co-authored-by: codex --- ...9-16_zacchua_fix-event-handler-account-scoping.change.md | 6 ++++++ stripe/_stripe_client.py | 1 - tests/test_event_notification_handler.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md diff --git a/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md b/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md new file mode 100644 index 000000000..083e4aa73 --- /dev/null +++ b/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md @@ -0,0 +1,6 @@ +--- +title: Fix account scoping for event notification handler callback clients +semver_level: patch +--- + +* Fix callback clients to use the event's Stripe context without inheriting the original client's Stripe account. diff --git a/stripe/_stripe_client.py b/stripe/_stripe_client.py index f2c01b076..1db63f0c1 100644 --- a/stripe/_stripe_client.py +++ b/stripe/_stripe_client.py @@ -353,7 +353,6 @@ def with_stripe_context( """ return StripeClient( api_key=self._requestor.api_key, # type: ignore - stripe_account=self._requestor._options.stripe_account, stripe_context=stripe_context, stripe_version=self._requestor._options.stripe_version, base_addresses=self._requestor._options.base_addresses, diff --git a/tests/test_event_notification_handler.py b/tests/test_event_notification_handler.py index c47460589..74dad1855 100644 --- a/tests/test_event_notification_handler.py +++ b/tests/test_event_notification_handler.py @@ -29,6 +29,7 @@ class TestEventNotificationHandler: def stripe_client(self, http_client_mock: HTTPClientMock) -> StripeClient: return StripeClient( api_key="sk_test_1234", + stripe_account="acct_123", stripe_context=StripeContext.parse("original_context_123"), http_client=http_client_mock.get_mock_http_client(), ) @@ -249,12 +250,14 @@ def test_handler_uses_event_stripe_context( ) -> None: """Test that the handler receives a client with stripe_context from the event""" received_context: Optional[StripeContext | str] = None + received_account: Optional[str] = None def handler( event: V1BillingMeterErrorReportTriggeredEventNotification, client: StripeClient, ) -> None: - nonlocal received_context + nonlocal received_account, received_context + received_account = client._requestor._options.stripe_account received_context = client._requestor._options.stripe_context event_handler.on_v1_billing_meter_error_report_triggered(handler) @@ -268,6 +271,7 @@ def handler( event_handler.handle(v1_billing_meter_payload, sig_header) assert str(received_context) == "event_context_456" + assert received_account is None def test_stripe_context_restored_after_handler_success( self, From 4771a7434fcb03350ed6133fbfa86a008d573eb2 Mon Sep 17 00:00:00 2001 From: Zachary Chua Date: Wed, 16 Sep 2026 12:03:56 -0700 Subject: [PATCH 2/2] Add PR URL to changefile Committed-By-Agent: codex Co-authored-by: codex --- ...-09-16_zacchua_fix-event-handler-account-scoping.change.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md b/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md index 083e4aa73..c8cc29ced 100644 --- a/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md +++ b/.hark/changes/2026-09-16_zacchua_fix-event-handler-account-scoping.change.md @@ -1,6 +1,8 @@ --- title: Fix account scoping for event notification handler callback clients +pr_url: https://github.com/stripe/stripe-python/pull/1911 semver_level: patch --- -* Fix callback clients to use the event's Stripe context without inheriting the original client's Stripe account. +- Fix callback clients to use the event's Stripe context and preserve the original client's non-account configuration. +- Fix API errors when using an event notification handler with a client configured with a Stripe account.