: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(bugsnag): cap releases endpoint page size at 10 (#72160)
Tom Owersc37eed9487f8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/bugsnag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/bugsnag.pyindex e77e31d5b5e6..7e4feafb9dab 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/bugsnag.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/bugsnag.py@@ -21,7 +21,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res# BugSnag uses a single global host for its Data Access API. On-prem / Enterprise installs use a# custom host, which this source does not yet support.BUGSNAG_BASE_URL = "https://api.bugsnag.com"-# BugSnag's documented per_page maximum for list endpoints.+# Default per_page for list endpoints. Endpoints that cap lower override it via+# BugsnagEndpointConfig.page_size (e.g. releases, which 400s on anything above 10).PAGE_SIZE = 100# The Data Access API is versioned via the X-Version header. v2 is current; v1 is decommissioned.BUGSNAG_API_VERSION = "2"@@ -184,7 +185,7 @@ def _iter_top_level(url = resume.next_urllogger.debug(f"BugSnag: resuming {config.name} from URL: {url}")else:- url = _build_url(f"{BUGSNAG_BASE_URL}{config.path}", {"per_page": PAGE_SIZE})+ url = _build_url(f"{BUGSNAG_BASE_URL}{config.path}", {"per_page": config.page_size})while True:items, next_url = _fetch_list_page(session, url, headers, logger)@@ -234,7 +235,7 @@ def _iter_fan_out(for index in range(start_index, len(parents)):parent = parents[index]path = config.path.format(**parent.path_kwargs)- url = resume_url or _build_url(f"{BUGSNAG_BASE_URL}{path}", {"per_page": PAGE_SIZE})+ url = resume_url or _build_url(f"{BUGSNAG_BASE_URL}{path}", {"per_page": config.page_size})resume_url = None # only the resumed-into parent uses the saved URL; the rest start freshwhile True:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/settings.pyindex d44a20bed860..a17262f43b7f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/settings.py@@ -36,6 +36,10 @@ class BugsnagEndpointConfig:# Stable, creation-time datetime column to partition by. Never a `last_seen`/`updated_at`# style field — those move and would rewrite partitions every sync. None disables partitioning.partition_key: Optional[str] = None+ # per_page value used when paginating this endpoint. Most list endpoints accept up to 100, but+ # a few cap lower and hard-reject an over-max value with a 400 instead of clamping, so those+ # need their own limit.+ page_size: int = 100# The menu of incremental cursor candidates advertised to the user. Empty = full refresh only.incremental_fields: list[IncrementalField] = field(default_factory=list)# Whether the table is selected for sync by default in the connection wizard.@@ -96,6 +100,8 @@ BUGSNAG_ENDPOINTS: dict[str, BugsnagEndpointConfig] = {path="/projects/{project_id}/releases",primary_keys=["id", "project_id"],partition_key="released_at",+ # This endpoint caps per_page at 10 and returns 400 for anything higher.+ page_size=10,),"pivots": BugsnagEndpointConfig(name="pivots",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/tests/test_bugsnag.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/tests/test_bugsnag.pyindex 84deb6b6200d..e117641a990d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/tests/test_bugsnag.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugsnag/tests/test_bugsnag.py@@ -251,6 +251,18 @@ class TestPerProjectFanOut:{"id": "e2", "organization_id": "o1", "project_id": "p2"},]+ def test_releases_caps_page_size_at_ten(self, monkeypatch: Any) -> None:+ # The releases endpoint rejects per_page above 10 with a 400, so it must request per_page=10+ # while the parent enumeration keeps the default 100. A per_page=100 releases URL is absent+ # from `pages`, so a regression would raise on the unexpected URL.+ pages = {+ "https://api.bugsnag.com/user/organizations?per_page=100": ([{"id": "o1"}], None),+ "https://api.bugsnag.com/organizations/o1/projects?per_page=100": ([{"id": "p1"}], None),+ "https://api.bugsnag.com/projects/p1/releases?per_page=10": ([{"id": "r1"}], None),+ }+ rows = _collect("releases", pages, _FakeResumableManager(), monkeypatch)+ assert rows == [{"id": "r1", "organization_id": "o1", "project_id": "p1"}]+class TestValidateCredentials:@parameterized.expand(