: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 cloudflare audit_logs sync failing on deep pagination (#78575)
Tom Owersb320d33d38c1
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/settings.pyindex 598a8421a883..68fd272d3a9f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/settings.py@@ -229,6 +229,12 @@ CLOUDFLARE_ENDPOINTS: dict[str, CloudflareEndpointConfig] = {# match SourceResponse's ascending sort mode.params={"direction": "asc"},incremental_param="since",+ # This list has no `result_info.total_pages`, so the paginator only learns it has+ # reached the end from a short page; when an account's true count is an exact+ # multiple of PAGE_SIZE, the page right past the end gets a 400 rather than an+ # empty list. Treat it like the end of the list — the next sync's `since` picks up+ # where this one stopped.+ extra_skip_status_codes=(400,),),"billing_usage": CloudflareEndpointConfig(name="billing_usage",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/tests/test_cloudflare_client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/tests/test_cloudflare_client.pyindex 65c8ae60f038..b905690fade9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/tests/test_cloudflare_client.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/tests/test_cloudflare_client.py@@ -369,6 +369,29 @@ class TestAccountFanout:assert [(r["ts"], r["_account_id"]) for r in rows] == [(1, "a2")]+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_audit_logs_stops_on_400_past_a_full_last_page(self, MockSession) -> None:+ # audit_logs has no result_info.total_pages, so a "short page" is the only way the+ # paginator learns it has reached the end. When an account's true count is an exact+ # multiple of PAGE_SIZE, the page right past the end is requested anyway, and+ # Cloudflare answers it with a 400 instead of an empty list. The rows already fetched+ # must survive rather than the whole sync failing.+ session = MockSession.return_value+ full_page = [{"id": str(i)} for i in range(PAGE_SIZE)]+ _wire(+ session,+ [+ _response([{"id": "a1"}], total_pages=1),+ _response(full_page),+ _error_response(400),+ ],+ )++ rows = _rows(cloudflare_source("token", "audit_logs", team_id=1, job_id="j"))++ assert len(rows) == PAGE_SIZE+ assert {r["_account_id"] for r in rows} == {"a1"}+class TestSinglePageEndpoints:@pytest.mark.parametrize(