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(clerk): stop paginator crashing on empty response body (#71427)

Tom Owerscc4e02021b1c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py
index 00b1ea640555..d820885a3566 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/clerk.py
@@ -75,6 +75,13 @@ class ClerkPaginator(BasePaginator):
request.params["offset"] = self._offset
def update_state(self, response: Response, data: list[Any] | None = None) -> None:
+ # A successful response with an empty body means there are no more rows.
+ # rest_client already treats this as an empty page (body=None); mirror
+ # that here instead of re-parsing and raising JSONDecodeError.
+ if not response.content or not response.content.strip():
+ self._has_next_page = False
+ return
+
res = response.json()
if not res:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py
index f9defdcdead0..39bd2e723077 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk.py
@@ -49,6 +49,19 @@ class TestClerkPaginator:
assert paginator._has_next_page is has_next
assert paginator._offset == expected_offset
+ def test_update_state_stops_on_empty_body(self) -> None:
+ # A 2xx response with an empty body must stop pagination, not crash on
+ # response.json() (Clerk returns this and it reached update_state raw).
+ response = Response()
+ response.status_code = 200
+ response._content = b""
+ paginator = ClerkPaginator(limit=100)
+
+ paginator.update_state(response)
+
+ assert paginator.has_next_page is False
+ assert paginator._offset == 0
+
@pytest.mark.parametrize(
("label", "seeded_offset", "expected_offset_param"),
[