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(mailchimp): classify exhausted 429/5xx retries as retryable (#80792)

Tom Owersb04852efa037
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/source.py
index 91a3307897e2..1a5ee9f71636 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/source.py
@@ -88,6 +88,15 @@ The API key format is: `key-dc` (e.g., `abc123def456-us6`), where `dc` is the da
"Invalid Mailchimp API key format": "Invalid API key format. Expected format: key-dc (e.g., abc123-us6)",
}
+ def get_retryable_errors(self) -> set[str]:
+ # `_mailchimp_session`'s `DEFAULT_RETRY` already retries 429/5xx responses in-process
+ # (Retry-After-aware backoff) before `raise_for_status()` can raise here. A response that
+ # still exhausts that budget is a transient Mailchimp/edge blip, not a bug — Temporal's
+ # activity retry recovers once it clears, so keep it out of error tracking as noise.
+ # `requests.Response.raise_for_status` derives these prefixes from the status code alone,
+ # not the vendor's reason text, so they're stable to match on.
+ return {"429 Client Error", "Server Error"}
+
def get_schemas(
self,
config: MailchimpSourceConfig,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/tests/test_mailchimp.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/tests/test_mailchimp.py
index 093adefc93db..8b73675969b0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/tests/test_mailchimp.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mailchimp/tests/test_mailchimp.py
@@ -27,6 +27,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mailchimp.
validate_credentials,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.mailchimp.settings import MAILCHIMP_ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.mailchimp.source import MailchimpSource
class TestExtractDataCenter:
@@ -906,3 +907,34 @@ class TestSourceResponseForNewEndpoints:
assert response.primary_keys == expected_primary_keys
assert response.partition_keys == expected_partition_keys
+
+
+class TestMailchimpRetryableErrors:
+ @pytest.mark.parametrize(
+ ("name", "observed_error"),
+ [
+ (
+ "429",
+ "429 Client Error: Too Many Requests for url: "
+ "https://us15.api.mailchimp.com/3.0/lists/c825cb5a63/members?count=1000&offset=0",
+ ),
+ ("500", "500 Server Error: Internal Server Error for url: https://us15.api.mailchimp.com/3.0/lists"),
+ ("502", "502 Server Error: Bad Gateway for url: https://us15.api.mailchimp.com/3.0/lists"),
+ ("503", "503 Server Error: Service Unavailable for url: https://us15.api.mailchimp.com/3.0/lists"),
+ ],
+ )
+ def test_transient_errors_are_recognised_as_retryable(self, name: str, observed_error: str) -> None:
+ retryable_errors = MailchimpSource().get_retryable_errors()
+ assert any(key in observed_error for key in retryable_errors), observed_error
+
+ @pytest.mark.parametrize(
+ ("name", "observed_error"),
+ [
+ ("401", "401 Client Error: Unauthorized for url: https://us15.api.mailchimp.com/3.0/lists"),
+ ("403", "403 Client Error: Forbidden for url: https://us15.api.mailchimp.com/3.0/lists"),
+ ("invalid_key_format", "Invalid Mailchimp API key format. Expected format: key-dc"),
+ ],
+ )
+ def test_non_retryable_errors_do_not_match(self, name: str, observed_error: str) -> None:
+ retryable_errors = MailchimpSource().get_retryable_errors()
+ assert not any(key in observed_error for key in retryable_errors), observed_error