: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): classify Stripe's generic 5xx error as retryable (#76152)
Tom Owersdcae63b3d054
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 daa1188cfdfb..9a6b1f6b1fee 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@@ -302,9 +302,11 @@ If automatic creation failed due to a permissions error and you're using a restr# 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"}+ # varies between several known phrasings, so match the boilerplate phrases they share rather+ # than the full message: "notified of the problem" covers Stripe's backend-communication+ # errors, and "An unknown error occurred" covers the generic 5xx it can't attribute to a more+ # specific cause (some of which arrive without the "notified" boilerplate).+ return {"Request rate limit exceeded", "notified of the problem", "An unknown error occurred"}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.pyindex 836b65cd10b7..819657cbc411 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@@ -233,33 +233,31 @@ class TestStripeSource:non_retryable_errors = self.source.get_non_retryable_errors()assert not any(key in other_error for key in non_retryable_errors)- @parameterized.expand(+ @pytest.mark.parametrize(+ "observed_error",[- (- # 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.",- ),- ]+ # 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.+ "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.",+ # Stripe's generic message for a 5xx it can't attribute to a specific cause, arriving+ # without the "notified of the problem" boilerplate. The SDK's own retry loop already+ # exhausted `max_network_retries` before this reaches us, so it's the same self-recovering+ # shape as an exhausted rate limit.+ "Request req_hOaEpFmCP1VADa: An unknown error occurred",+ ],)- 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.+ def test_retryable_errors_match_transient_stripe_errors(self, observed_error):+ # Matched 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 error_message_matches(observed_error, retryable_errors)