:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(stripe): treat an Organization API key as a non-retryable credential error (#130945)
Tom Owers232d0d970bc5
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.pyindex 6de2094ae389..d337c0c8ded8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py@@ -412,6 +412,11 @@ If automatic creation failed with a permissions error, the fix depends on how yo# Publishable keys can't authenticate any of the read endpoints we sync, so every retry# fails identically — match Stripe's stable rejection text (the request id varies)."This API call cannot be made with a publishable API key": "Your Stripe API key is a publishable key, which cannot be used to sync data. Please use a secret or restricted key instead, then reconnect.",+ # The customer pasted an Organization API key, which Stripe scopes to no single account —+ # every request needs a target account via a Stripe-Context header, which we never send.+ # Every endpoint we sync fails identically, so retrying can't help; Stripe's own text is+ # stable (no request id or account id embedded).+ "Please include the Stripe-Context header with your target account when using an Organization API key": "Your Stripe API key is an Organization API key, which isn't supported. Please use a secret or restricted API key scoped to a single Stripe account instead, then reconnect.",# A non-Connect key was sent with a `stripe_account` header (the source's "Account id"),# so Stripe rejects the whole request for the account rather than a specific scope."Only Stripe Connect platforms can work with other accounts": "Stripe rejected the request because your API key isn't authorized for the configured Stripe account. The 'Account id' in your source settings only applies to Stripe Connect platform accounts — remove or correct it if your key belongs directly to the account, then reconnect.",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.pyindex e0e4de22dee3..340850190257 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py@@ -543,6 +543,9 @@ class TestStripeSource:# The key belongs to a connected account, so Stripe refuses to nest Connect access two# levels deep when an "Account id" is also configured — a customer misconfiguration."Request req_abc123: You cannot access the connected accounts of your platform's connected accounts.",+ # An Organization API key was used — Stripe rejects every request that omits the+ # Stripe-Context header these keys require, matched on the stable boilerplate text.+ "Please include the Stripe-Context header with your target account when using an Organization API key.",],)def test_non_retryable_errors_match_permission_failures(self, observed_error):@@ -583,6 +586,22 @@ class TestStripeSource:assert messages[0] is not Noneassert "Account id" in messages[0]+ def test_organization_api_key_rejection_has_actionable_message(self):+ # Stripe's own text doesn't say which key type the customer should use instead, so the+ # guidance has to name it — every call with an Organization key fails identically, since+ # it never carries the Stripe-Context header these keys require.+ observed_error = (+ "Please include the Stripe-Context header with your target account when using an Organization API key."+ )+ messages = [+ message+ for pattern, message in self.source.get_non_retryable_errors().items()+ if error_message_matches(observed_error, [pattern])+ ]+ assert messages+ assert messages[0] is not None+ assert "secret or restricted API key" in messages[0]+@pytest.mark.parametrize("other_error",[