Skip to content

: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.

fix(stripe): stop retrying when the account can't list connected accounts (#104098)

Tom Owersa2eae97162fa
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.py
index b7453f8180b5..eeed40b9522b 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
@@ -297,6 +297,13 @@ If automatic creation failed with a permissions error, the fix depends on how yo
# of the substring). `_is_stripe_account_access_error` classifies the same phrase for the
# webhook-creation path.
"does not have access to account": "Stripe rejected the request because your API key isn't authorized for the configured Stripe account. Remove or correct the 'Account id' in your source settings if your key belongs directly to the account. If you connected via OAuth, the application access may have been revoked — reconnect your Stripe account.",
+ # The key itself belongs to a connected account (not the platform), so Stripe refuses the
+ # `stripe_account` header (the source's "Account id") outright — nesting Connect access
+ # two levels deep isn't supported. This surfaces on every endpoint the sync calls with
+ # that header set (observed on `disputes.list`, not just `accounts.list`), so the fix is
+ # the account/key configuration, not any one table. Same customer misconfiguration as the
+ # platform-only rejection above, just Stripe's other wording for it.
+ "connected accounts of your platform's connected accounts": "Stripe rejected the request because your API key belongs to a connected account, which cannot access other connected accounts. Remove the 'Account id' in your source settings, or use a platform API key instead, then reconnect.",
# Deterministic credential/config errors from _get_api_key and OAuthMixin
"Missing Stripe API key": "Stripe API key is not configured. Please update the source configuration.",
"Missing Stripe integration ID": "Stripe integration ID is not configured. Please reconnect your Stripe account.",
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.py
index 4f55932fe5b2..a8db53c839bb 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
@@ -247,6 +247,9 @@ class TestStripeSource:
# listing a specific customer's nested resources — every retry replays the same request
# against the same customer and fails identically.
"Request req_abc123: error_details_unknown",
+ # 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.",
],
)
def test_non_retryable_errors_match_permission_failures(self, observed_error):
@@ -271,6 +274,22 @@ class TestStripeSource:
assert messages[0] is not None
assert "isn't authorized for the configured Stripe account" in messages[0]
+ def test_connect_account_topology_rejection_has_actionable_message(self):
+ # Stripe's own text names no fix a customer can act on — the guidance has to say what will,
+ # which is removing the 'Account id' or switching to a platform key, since the rejection is
+ # about the key/account combination and surfaces on any endpoint the sync calls, not one table.
+ observed_error = (
+ "Request req_abc123: You cannot access the connected accounts of your platform's connected accounts."
+ )
+ 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 "Account id" in messages[0]
+
@pytest.mark.parametrize(
"other_error",
[