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): classify Stripe's generic backend-error APIError as retryable (#76351)

Tom Owers073978880bb6
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 b1914956db92..daa1188cfdfb 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
@@ -298,7 +298,13 @@ If automatic creation failed due to a permissions error and you're using a restr
# A 429 is already retried in-process by _RateLimitRetryingRequestsClient's Retry-After-aware
# backoff (see stripe.py); if that budget still exhausts, Temporal's activity retry picks it
# back up, so this is self-recovering rather than a tracked-exception-worthy failure.
- return {"Request rate limit exceeded"}
+ #
+ # A non-4xx `stripe.APIError` (a genuine backend problem on Stripe's side) is already retried
+ # in-process by the SDK's own 5xx backoff before it can reach here, so the same reasoning
+ # applies. Stripe's docs describe these as safe to retry. The server-generated message text
+ # varies between at least two known phrasings, so match the boilerplate phrase both share
+ # rather than the full message.
+ return {"Request rate limit exceeded", "notified of the problem"}
def _get_api_key(self, config: StripeSourceConfig, team_id: int) -> str:
if config.auth_method.selection == "api_key":
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 57dc7a97423c..836b65cd10b7 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
@@ -10,6 +10,7 @@ import stripe as stripe_lib
from parameterized import parameterized
from stripe import ListObject
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matches
from products.warehouse_sources.backend.temporal.data_imports.sources.common.webhook_s3 import WebhookSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.stripe import (
StripeAuthMethodConfig,
@@ -232,16 +233,35 @@ class TestStripeSource:
non_retryable_errors = self.source.get_non_retryable_errors()
assert not any(key in other_error for key in non_retryable_errors)
- def test_retryable_errors_match_rate_limit(self):
- # A RateLimitError that survives _RateLimitRetryingRequestsClient's in-process backoff still
- # gets retried by Temporal at the activity level; it must be classified as retryable so it's
- # logged as a warning rather than tracked as an exception.
- observed_error = (
- "Request req_abc123: Request rate limit exceeded. You can learn more about rate limits here "
- "https://stripe.com/docs/rate-limits."
- )
+ @parameterized.expand(
+ [
+ (
+ # A RateLimitError that survives _RateLimitRetryingRequestsClient's in-process backoff
+ # still gets retried by Temporal at the activity level.
+ "Request req_abc123: Request rate limit exceeded. You can learn more about rate limits here "
+ "https://stripe.com/docs/rate-limits.",
+ ),
+ (
+ # A generic backend APIError that survives the SDK's own in-process 5xx retries — one
+ # of at least two known server-generated phrasings for the same "our fault, try again"
+ # condition.
+ "Request req_abc123: Error while communicating with one of our backends. Sorry about "
+ "that! We have been notified of the problem. If you have any questions, we can help "
+ "at https://support.stripe.com/.",
+ ),
+ (
+ "Request req_abc123: Sorry, something went wrong. We've already been notified of the "
+ "problem, but if you need any help, you can reach us at https://support.stripe.com/contact.",
+ ),
+ ]
+ )
+ def test_retryable_errors_match_self_recovering_errors(self, observed_error):
+ # These must be classified as retryable so they're logged as a warning rather than tracked
+ # as an exception, since they're retried by Temporal at the activity level regardless. Match
+ # via the same case-insensitive helper the production path uses (`_handle_import_error`),
+ # not a case-sensitive substring check.
retryable_errors = self.source.get_retryable_errors()
- assert any(key in observed_error for key in retryable_errors)
+ assert error_message_matches(observed_error, retryable_errors)
@pytest.mark.parametrize(
"config,expected_message",