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): skip a funnel Mixpanel rejects instead of aborting the sync (#115607)

Tom Owers50c78922b565
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py
index edb439a22bd6..1ef842f2571e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py
@@ -528,7 +528,20 @@ def _iter_funnel_steps(
"to_date": end_date.isoformat(),
"unit": "day",
}
- response = _request("GET", url, username=username, secret=secret, logger=logger, params=params)
+ try:
+ response = _request("GET", url, username=username, secret=secret, logger=logger, params=params)
+ except requests.HTTPError as e:
+ # Mixpanel rejects some saved funnels outright (e.g. deleted since the funnel list
+ # was fetched) with a 400 tied to that funnel_id alone, not the request shape. Without
+ # this, one such funnel would raise every attempt and the resume cursor would never
+ # advance past it, permanently blocking every funnel after it in the sort order.
+ if e.response is None or e.response.status_code != 400:
+ raise
+ logger.warning(f"Mixpanel funnel_steps: Mixpanel rejected funnel {funnel_id}; skipping it")
+ manager.save_state(MixpanelResumeConfig(funnel_id=funnel_id))
+ manager.safe_point()
+ continue
+
rows = _flatten_funnel_steps(funnel, response.json())
manager.save_state(MixpanelResumeConfig(funnel_id=funnel_id))
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py
index 12c44a5ff6a7..563ef57e5403 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py
@@ -530,6 +530,27 @@ class TestReportEndpoints:
(9, "Checkout", "2024-06-03", 0, "Signup"),
]
+ def test_funnel_steps_skips_funnel_rejected_with_400_and_resumes_past_it(self) -> None:
+ manager = FakeManager()
+ funnel_list = FakeResponse(json_data=[{"funnel_id": 9, "name": "Checkout"}, {"funnel_id": 7, "name": "Signup"}])
+ rejected = FakeResponse(status_code=400)
+
+ def fake_request(method: str, url: str, **kwargs: Any) -> FakeResponse:
+ if url.endswith("/funnels/list"):
+ return funnel_list
+ if kwargs["params"]["funnel_id"] == 7:
+ raise requests.HTTPError("400 Client Error", response=rejected) # type: ignore[arg-type]
+ return self._funnel_response()
+
+ with patch.object(mp, "_request", side_effect=fake_request):
+ batches = list(mp.get_rows("us", "u", "s", "123", "funnel_steps", LOGGER, manager)) # type: ignore[arg-type]
+
+ # Funnel 7 is rejected but the resume cursor still advances past it, so funnel 9
+ # (and any funnel after a rejected one) still syncs instead of the whole sync aborting.
+ assert [s.funnel_id for s in manager.saved] == [7, 9]
+ rows = [row for batch in batches for row in batch]
+ assert [r["funnel_id"] for r in rows] == [9, 9, 9]
+
def test_retention_requests_compounded_retention_and_unnests_cohorts(self) -> None:
response = FakeResponse(
json_data={"2024-06-03": {"counts": [8], "first": 8}, "2024-06-02": {"counts": [10, 6], "first": 10}}