: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(data-imports): carry filter[status] across mailerlite automation activity pages (#116483)
Tom Owers6f1f1986e806
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/mailerlite.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/mailerlite.pyindex ef9a97d99f3c..dab9c1fea0ac 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/mailerlite.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/mailerlite.py@@ -2,7 +2,7 @@ import dataclassesfrom collections.abc import Iteratorfrom datetime import UTC, datetimefrom typing import Any, Optional-from urllib.parse import urlsplit+from urllib.parse import parse_qsl, urlencode, urlsplitimport orjsonimport pyarrow as pa@@ -58,6 +58,29 @@ class MailerLiteResumeConfig:child_state: dict[str, Any] | None = None+# The automation activity endpoint requires `filter[status]` on every page (see api_inventory.md),+# but MailerLite's own `links.next` for page 2+ omits it — following that link verbatim 422s with+# "Unprocessable Entity". Carry it forward from the page that was just fetched.+_CARRIED_QUERY_PARAMS = ("filter[status]",)+++def _carry_required_query_params(next_url: str, previous_url: Optional[str]) -> str:+ if not previous_url:+ return next_url++ previous_query = dict(parse_qsl(urlsplit(previous_url).query))+ next_split = urlsplit(next_url)+ next_query = parse_qsl(next_split.query)+ next_keys = {key for key, _ in next_query}+ missing = [+ (key, previous_query[key]) for key in _CARRIED_QUERY_PARAMS if key in previous_query and key not in next_keys+ ]+ if not missing:+ return next_url++ return next_split._replace(query=urlencode(next_query + missing)).geturl()++class MailerLiteNextUrlPaginator(JSONResponsePaginator):"""Follows the absolute ``links.next`` URL MailerLite returns for both cursor (subscribers) andpage-number (everything else) pagination — but only while it stays on the canonical MailerLite@@ -72,6 +95,8 @@ class MailerLiteNextUrlPaginator(JSONResponsePaginator):def update_state(self, response: Response, data: Optional[list[Any]] = None) -> None:super().update_state(response, data)+ if self._has_next_page and self._next_url is not None:+ self._next_url = _carry_required_query_params(self._next_url, response.url)if self._has_next_page and (not isinstance(self._next_url, str) or not self._next_url.startswith(MAILERLITE_BASE_URL)):diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/tests/test_mailerlite.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/tests/test_mailerlite.pyindex 99e834c6d2f8..a112402b7ce9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/tests/test_mailerlite.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mailerlite/tests/test_mailerlite.py@@ -190,6 +190,23 @@ class TestFanout:assert {row["automation_id"] for row in result.rows} == {"au1"}assert "activity_status" not in result.rows[0]+ def test_automation_activity_pagination_carries_filter_status(self) -> None:+ # MailerLite's own `links.next` for this endpoint drops the required `filter[status]`+ # on page 2+ (it only carries `page`); the paginator must re-attach it from page 1's+ # request or the next request 422s.+ child_next = f"{MAILERLITE_BASE_URL}/automations/au1/activity?page=2"+ result = _driver().run(+ "automation_activity",+ [_page([{"id": "au1"}], None)]+ + [_page([{"id": "run-active-1"}], child_next), _page([{"id": "run-active-2"}], None)]+ + [_page([{"id": f"run-{status}"}], None) for status in ("completed", "canceled", "failed")],+ )++ assert result.raised is None+ assert result.params("filter[status]")[1:3] == ["active", "active"]+ assert result.params("page")[2] == "2"+ assert {row["id"] for row in result.rows} >= {"run-active-1", "run-active-2"}+def test_resume_skips_completed_parents(self) -> None:result = _driver().run("group_subscribers",