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(rollbar): stop page pagination gracefully on a 422 past the ceiling (#117212)

Tom Owers5cded58e6aae
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/rollbar.py b/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/rollbar.py
index 71ca920e27f9..019cae865468 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/rollbar.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/rollbar.py
@@ -154,8 +154,21 @@ def get_rows(
if resume_config is not None:
logger.debug(f"Rollbar: resuming {endpoint} from page {page}")
+ is_first_page = True
while True:
- body = fetch(_build_url(config.path, {"page": page}))
+ try:
+ body = fetch(_build_url(config.path, {"page": page}))
+ except requests.HTTPError as e:
+ # Rollbar's page-paginated list endpoints (items, deploys, environments) reject a page
+ # past an undocumented depth ceiling with a 422 instead of an empty page. That's
+ # deterministic — retrying never clears it — so once this run has already pulled at
+ # least one page, we treat the 422 as end-of-data rather than failing the whole sync. A
+ # 422 on the first fetch is left to propagate: Rollbar hasn't told us any page works.
+ if not is_first_page and e.response is not None and e.response.status_code == 422:
+ logger.warning(f"Rollbar: pagination ceiling reached on {endpoint}; stopping this sync early")
+ break
+ raise
+ is_first_page = False
items = _extract_items(body, config.data_key)
if not items:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/tests/test_rollbar.py b/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/tests/test_rollbar.py
index ced7a6233010..b82c8dde8fc2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/tests/test_rollbar.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/rollbar/tests/test_rollbar.py
@@ -2,6 +2,8 @@ from typing import Any
import pytest
+import requests
+
from products.warehouse_sources.backend.temporal.data_imports.sources.common.testing import (
ScriptedResponse,
SourceDriver,
@@ -113,6 +115,27 @@ class TestGetRowsPagePagination:
assert result.items == [[{"id": 1, "environment": "production"}]]
+ def test_pagination_ceiling_422_stops_after_first_page(self):
+ # Rollbar rejects a page past an undocumented depth ceiling with a 422 instead of an
+ # empty page. Once a page has already come back, that's end-of-data, not a failure.
+ result = _driver().run(
+ "items",
+ [
+ _response("items", [{"id": 1}]),
+ ScriptedResponse(status=422),
+ ],
+ )
+
+ assert result.raised is None
+ assert result.items == [[{"id": 1}]]
+
+ def test_pagination_ceiling_422_on_first_page_propagates(self):
+ # A 422 before any page has succeeded isn't a depth ceiling — Rollbar hasn't told us any
+ # page works, so it must surface rather than being read as an empty sync.
+ result = _driver().run("items", [ScriptedResponse(status=422)])
+
+ assert isinstance(result.raised, requests.HTTPError)
+
class TestGetRowsKeyset:
def test_walks_keyset_descending(self):