: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): show the actionable message when a key can't reach the account (#96463)
Tom Owers6c428482b483
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 a9128fba893a..99e6ddbf23d1 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@@ -265,6 +265,9 @@ If automatic creation failed with a permissions error, the fix depends on how yo)def get_non_retryable_errors(self) -> dict[str, str | None]:+ # Order matters: the finalization activity shows the message of the *first* pattern that+ # matches, so keys that carry actionable copy come before the catch-alls that surface+ # Stripe's own text.return {"401 Client Error: Unauthorized for url: https://api.stripe.com": "Your Stripe credentials do not have permissions to access endpoint. Please check your configuration and permissions in Stripe, then try again.","403 Client Error: Forbidden for url: https://api.stripe.com": "Your Stripe credentials do not have permissions to access endpoint. Please check your configuration and permissions in Stripe, then try again.",@@ -274,18 +277,6 @@ If automatic creation failed with a permissions error, the fix depends on how yo# include PostHog's egress IPs. This is a customer-side key configuration that retrying# can never satisfy, so stop retrying. Match the stable phrase, not the appended IP."does not allow requests from your IP address": "Your Stripe API key restricts requests by IP address and is blocking PostHog. Remove the IP restriction on your restricted key in Stripe (or allowlist PostHog's IP addresses), then try again.",- # Surface Stripe's raw permission message — it names the specific scope that's missing- # (e.g. "Having the 'rak_payment_method_read' permission would allow this request to- # continue"), which is more actionable than a generic "check your permissions" toast.- # `_clean_stripe_error_message` collapses the redacted-key asterisk run before the- # message reaches this layer, so it stays toast-sized.- #- # NOTE: this `"PermissionError"` key only matches the refresh-schemas path, which compares- # against `f"{type(error).__name__}: {message}"`. The import/sync path compares against- # `str(exc)` only — and `StripeError.__str__` returns `"Request <id>: <message>"` with no- # class name — so the type-name key never matches a 403 raised mid-sync. Match Stripe's- # stable permission-denied message text directly so a misconfigured key stops retrying.- "PermissionError": None,# Restricted key is missing a read scope for the endpoint being synced (e.g. "Prices Read"# / 'plan_read'). The customer must add the scope in Stripe — retrying won't help. Surface# Stripe's raw message (None) since it names the exact scope to enable.@@ -318,6 +309,18 @@ If automatic creation failed with a permissions error, the fix depends on how yo# identically every time. Stripe's own message isn't actionable, so surface a message# that points at the account rather than showing the raw string."error_details_unknown": "Stripe rejected a request for one of your resources without a specific reason. Check your Stripe account for any restrictions or contact Stripe support, then try again.",+ # Catch-all for every other `stripe.PermissionError`, surfacing Stripe's raw permission+ # message (None) because it names the specific scope that's missing (e.g. "Having the+ # 'rak_payment_method_read' permission would allow this request to continue").+ # `_clean_stripe_error_message` collapses the redacted-key asterisk run before the+ # message reaches this layer, so it stays toast-sized.+ #+ # Last on purpose. The message this is matched against carries the failing exception+ # class (Temporal renders a wrapped activity failure as `<ExceptionClass>: <message>`),+ # so this key matches every permission failure raised mid-sync — including the ones the+ # keys above already explain. Ordered any earlier it wins the first-match and strands+ # those failures on Stripe's raw text.+ "PermissionError": None,}def get_retryable_errors(self) -> set[str]: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 7d4d1e627831..50e70cd02dce 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@@ -248,6 +248,24 @@ class TestStripeSource:non_retryable_errors = self.source.get_non_retryable_errors()assert any(key in observed_error for key in non_retryable_errors)+ def test_account_access_rejection_keeps_its_actionable_message(self):+ # The finalization activity shows the first matching pattern's message, and matches against+ # a message Temporal prefixes with the failing exception class. The generic "PermissionError"+ # key therefore matches this failure too, and ordering it first left the customer Stripe's+ # raw text — which echoes their key and account id back at them — instead of the guidance.+ observed_error = (+ "PermissionError: The provided key 'rk_live_***AAAA' does not have access to account "+ "'acct_example' (or that account does not exist). Application access may have been revoked."+ )+ 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 "isn't authorized for the configured Stripe account" in messages[0]+@pytest.mark.parametrize("other_error",[