: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): stop next-url paginator from re-appending original params (#71382)
Tom Owersf465aa3bc516
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/paginators.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/paginators.pyindex 30c8dc642a40..70298f4df38f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/paginators.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/paginators.py@@ -53,6 +53,12 @@ class BaseNextUrlPaginator(BasePaginator):def update_request(self, request: Request) -> None:if self._next_url is not None:request.url = self._next_url+ # The next-page URL is self-contained — it already carries every query+ # param needed. Drop the original params so `prepare_request` doesn't+ # re-append them to the URL each page; some APIs echo the received query+ # back into their next link, so re-appending compounds one copy per page+ # until the URL grows large enough for the server to reject it.+ request.params = {}class HeaderLinkPaginator(BaseNextUrlPaginator):diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_paginators.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_paginators.pyindex 8a5e5ab917e3..738bb086f358 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_paginators.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_paginators.py@@ -3,7 +3,7 @@ from typing import Anyimport pytest-from requests import Request, Response+from requests import PreparedRequest, Request, Response, Sessionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (HeaderLinkPaginator,@@ -71,6 +71,40 @@ class TestJSONResponsePaginator:def test_json_link_paginator_is_alias(self) -> None:assert JSONLinkPaginator is JSONResponsePaginator+ def test_clears_original_params_when_following_next_url(self) -> None:+ # The initial request carries query params (e.g. per_page + an incremental+ # filter). Once the paginator switches to the server's self-contained next+ # URL, those params must be dropped — otherwise prepare_request re-appends+ # them to the already-complete URL, and an API that echoes the query back+ # into its next link compounds a duplicate every page (observed: an Intercom+ # activity_logs URL grew hundreds of `created_at_after=0` copies until 500).+ p = JSONResponsePaginator(next_url_path="pages.next")+ next_url = "https://api.example.com/logs?per_page=150&created_at_after=0&page=2"+ p.update_state(_make_response({"pages": {"next": next_url}, "activity_logs": []}))+ req = Request(+ method="GET",+ url="https://api.example.com/logs",+ params={"per_page": 150, "created_at_after": 0},+ )+ p.update_request(req)++ prepared: PreparedRequest = Session().prepare_request(req)+ assert prepared.url is not None+ assert prepared.url.count("created_at_after") == 1+ assert prepared.url.count("per_page") == 1++ def test_header_link_paginator_clears_original_params(self) -> None:+ p = HeaderLinkPaginator()+ resp = _make_response()+ resp.headers["Link"] = '<https://api.example.com/page2?per_page=150>; rel="next"'+ p.update_state(resp)+ req = Request(method="GET", url="https://api.example.com/page1", params={"per_page": 150})+ p.update_request(req)++ prepared: PreparedRequest = Session().prepare_request(req)+ assert prepared.url is not None+ assert prepared.url.count("per_page") == 1+class TestJSONResponseCursorPaginator:def test_follows_cursor(self) -> None: