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(mixpanel): stop retrying 402 Payment Required on cohorts endpoint (#92106)

Tom Owerse259236535b2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/source.py
index 1350fcd73875..0682f6884abf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/source.py
@@ -171,6 +171,12 @@ Authenticate with a [Mixpanel Service Account](https://developer.mixpanel.com/re
"The Mixpanel service account does not have access to this project or resource. Grant it "
"access to the project and reconnect."
),
+ # Mixpanel returns 402 when the project's plan does not include the data export API or the
+ # account is in a payment-overdue state. Retrying cannot resolve a billing issue.
+ "402 Client Error: Payment Required": (
+ "Mixpanel requires a paid plan that includes the data export API. Check your Mixpanel "
+ "plan and billing status, then try again."
+ ),
}
def get_retryable_errors(self) -> set[str]:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel_source.py
index ae1e35b6c6b1..253c5551add9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel_source.py
@@ -132,3 +132,26 @@ class TestSourceForPipeline:
),
)
assert mock_source.call_args.kwargs["db_incremental_field_last_value"] is None
+
+
+class TestNonRetryableErrors:
+ source = MixpanelSource()
+
+ @parameterized.expand(
+ [
+ ("401", "401 Client Error: Unauthorized for url: https://mixpanel.com/api/query/cohorts/list"),
+ ("403", "403 Client Error: Forbidden for url: https://mixpanel.com/api/query/engage"),
+ ("402", "402 Client Error: Payment Required for url: https://mixpanel.com/api/query/cohorts/list"),
+ ]
+ )
+ def test_billing_and_auth_failures_are_non_retryable(self, _name: str, observed_error: str) -> None:
+ assert any(key in observed_error for key in self.source.get_non_retryable_errors())
+
+ @parameterized.expand(
+ [
+ ("429", "429 Client Error: Too Many Requests for url: https://mixpanel.com/api/query/engage"),
+ ("500", "500 Server Error: Internal Server Error for url: https://mixpanel.com/api/query/engage"),
+ ]
+ )
+ def test_transient_failures_stay_retryable(self, _name: str, other_error: str) -> None:
+ assert not any(key in other_error for key in self.source.get_non_retryable_errors())