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(data-warehouse): send filter=all when listing netlify sites (#78127)

jake sciotto60d73832577c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/netlify.py b/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/netlify.py
index 9c2957eb96d1..aba35e9be5e8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/netlify.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/netlify.py
@@ -7,6 +7,10 @@ RFC-5988 `Link` headers (rel="next") for traversal — driven here by the framew
(we attach the account token to every request, so following an off-host or scheme-downgraded link
would leak it; refuse instead).
+`/sites` must be requested with `filter=all`: its undocumented default returns only sites the
+token's user personally owns, silently omitting team sites — and with it every site-scoped fan-out
+(netlify/open-api#225).
+
No list endpoint accepts a server-side timestamp filter, so every table is full refresh — there is
no reliable server-side cursor to sync incrementally on. The source is still resumable: top-level
lists checkpoint the next page URL, and fan-out tables checkpoint the framework's per-parent fan-out
@@ -178,7 +182,7 @@ def _build_top_level_resource(
) -> Resource:
endpoint: Endpoint = {
"path": config.path,
- "params": _params_with_page_size(config.page_size),
+ "params": _params_with_page_size(config.page_size, config.extra_params),
"paginator": NetlifyHeaderLinkPaginator(),
}
if config.redact_keys:
@@ -236,7 +240,7 @@ def _build_fan_out_resource(
"name": parent_config.name,
"endpoint": {
"path": parent_config.path,
- "params": _params_with_page_size(parent_config.page_size),
+ "params": _params_with_page_size(parent_config.page_size, parent_config.extra_params),
"paginator": NetlifyHeaderLinkPaginator(),
},
}
@@ -245,11 +249,12 @@ def _build_fan_out_resource(
"params": _params_with_page_size(
config.page_size,
{
+ **config.extra_params,
config.fan_out_path_param: {
"type": "resolve",
"resource": parent_config.name,
"field": config.fan_out_parent_field,
- }
+ },
},
),
"paginator": NetlifyCappedHeaderLinkPaginator(config.max_pages_per_parent, context={"table": config.name}),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/settings.py
index 2e51be135491..dff9c0e14e4f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/settings.py
@@ -39,6 +39,9 @@ class NetlifyEndpointConfig:
fan_out_include_parent_fields: Optional[dict[str, str]] = None
# Hard cap on pages fetched per parent in a fan-out, bounding a runaway paginator. Logged on hit.
max_pages_per_parent: int = 100
+ # Static query params sent on every request to this endpoint (on top of `per_page` and, for
+ # fan-out children, the resolve param — which always wins a key collision).
+ extra_params: dict[str, str] = field(default_factory=dict)
# Credential-bearing fields dropped from every row before it's persisted, so they never land in
# a queryable warehouse table. Dotted paths reach nested objects (e.g. `default_hooks_data.access_token`);
# a bare name targets a top-level field. A missing key is a no-op.
@@ -50,6 +53,11 @@ NETLIFY_ENDPOINTS: dict[str, NetlifyEndpointConfig] = {
name="sites",
path="/sites",
partition_key="created_at",
+ # Without `filter=all`, /sites only returns sites the token's user personally owns — team
+ # sites are silently omitted (empty for tokens whose user created no site themselves), which
+ # also starves every site-scoped fan-out below. Netlify's own CLI sends filter=all; see
+ # https://github.com/netlify/open-api/issues/225.
+ extra_params={"filter": "all"},
# A site object carries account credentials a warehouse user shouldn't read: the site's
# basic-auth `password`, the `default_hooks_data.access_token`, and the build-time
# environment variables under `build_settings.env` (which routinely hold API secrets).
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/tests/test_netlify.py b/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/tests/test_netlify.py
index 5f76314c70a3..738f00843289 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/tests/test_netlify.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/netlify/tests/test_netlify.py
@@ -80,10 +80,11 @@ class TestTopLevelPagination:
@mock.patch(CLIENT_SESSION_PATCH)
def test_paginates_and_checkpoints_after_each_page(self, MockSession) -> None:
session = MockSession.return_value
+ next_url = f"{BASE}/sites?filter=all&page=2&per_page=100" # Netlify echoes the query, filter included
snaps = _wire(
session,
[
- _response([{"id": "a"}], next_url=f"{BASE}/sites?page=2&per_page=100"),
+ _response([{"id": "a"}], next_url=next_url),
_response([{"id": "b"}], next_url=None),
],
)
@@ -92,15 +93,20 @@ class TestTopLevelPagination:
assert rows == [{"id": "a"}, {"id": "b"}]
assert snaps[0]["params"]["per_page"] == 100
- # The next-page URL is self-contained, so its params are dropped on the follow-up request.
+ # filter=all is load-bearing: without it Netlify returns only sites the token's user
+ # personally owns, hiding team sites (and starving every site-scoped fan-out).
+ assert snaps[0]["params"]["filter"] == "all"
+ # The next-page URL is followed verbatim (params dropped, not re-appended), so the filter
+ # rides along to every subsequent page.
+ assert snaps[1]["url"] == next_url
assert snaps[1]["params"] == {}
# State saved once — after the first page, pointing at the second. The last page has no next
# link, so nothing is saved for it.
- manager.save_state.assert_called_once_with(NetlifyResumeConfig(next_url=f"{BASE}/sites?page=2&per_page=100"))
+ manager.save_state.assert_called_once_with(NetlifyResumeConfig(next_url=next_url))
@mock.patch(CLIENT_SESSION_PATCH)
def test_resumes_from_saved_url(self, MockSession) -> None:
- resume_url = f"{BASE}/sites?page=3&per_page=100"
+ resume_url = f"{BASE}/sites?filter=all&page=3&per_page=100"
session = MockSession.return_value
snaps = _wire(session, [_response([{"id": "c"}], next_url=None)])
manager = _manager(NetlifyResumeConfig(next_url=resume_url))
@@ -174,7 +180,7 @@ class TestFanOut:
session = MockSession.return_value
def route(url: str) -> Response:
- if url == f"{BASE}/sites?per_page=100":
+ if url == f"{BASE}/sites?filter=all&per_page=100":
return _response([{"id": "s1"}], next_url=None)
if url == f"{BASE}/sites/s1/builds?per_page=100":
return _response([{"id": "b1"}], next_url=None)
@@ -213,7 +219,7 @@ class TestFanOut:
session = MockSession.return_value
def route(url: str) -> Response:
- if url == f"{BASE}/sites?per_page=100":
+ if url == f"{BASE}/sites?filter=all&per_page=100":
return _response([{"id": "s1"}, {"id": "s2"}], next_url=None)
if url == f"{BASE}/sites/s2/builds?per_page=100":
return _response([{"id": "b2"}], next_url=None)