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-imports): skip cloudflare zones/accounts missing a plan feature during fan-out (#74538)

Tom Owersd5d3a997dda7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/cloudflare.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/cloudflare.py
index 0e2d15876b8a..1442cf760283 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/cloudflare.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cloudflare/cloudflare.py
@@ -286,7 +286,8 @@ def _fanout_resource(
child_endpoint = _endpoint(config, params, should_use_incremental_field)
child_endpoint["response_actions"] = [
- {"status_code": status, "action": "ignore"} for status in FANOUT_SKIP_STATUS_CODES
+ {"status_code": status, "action": "ignore"}
+ for status in (*FANOUT_SKIP_STATUS_CODES, *config.extra_skip_status_codes)
]
child = _resource(endpoint, child_endpoint)
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.py
index 2a8e1656b5e2..598a8421a883 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
@@ -40,6 +40,10 @@ class CloudflareEndpointConfig:
params: dict[str, Any] = field(default_factory=dict)
# Query param carrying the incremental watermark, when the API filters server-side.
incremental_param: Optional[str] = None
+ # Extra per-parent status codes to skip (in addition to FANOUT_SKIP_STATUS_CODES) —
+ # for endpoints where Cloudflare returns a non-403/404 error on a plan/feature that
+ # a specific zone or account doesn't have, rather than on missing read access.
+ extra_skip_status_codes: tuple[int, ...] = ()
# Most Cloudflare v4 REST lists are small configuration tables with no updated-since
@@ -88,6 +92,10 @@ CLOUDFLARE_ENDPOINTS: dict[str, CloudflareEndpointConfig] = {
path="/zones/{zone_id}/rate_limits",
parent=ZONES_PARENT,
parent_key="_zone_id",
+ # Cloudflare deprecated the legacy Rate Limiting Rules API in favor of the
+ # Ruleset Engine; zones without legacy rules get a 410 Gone rather than an
+ # empty list.
+ extra_skip_status_codes=(410,),
),
"bot_management": CloudflareEndpointConfig(
name="bot_management",
@@ -174,6 +182,8 @@ CLOUDFLARE_ENDPOINTS: dict[str, CloudflareEndpointConfig] = {
path="/zones/{zone_id}/custom_certificates",
parent=ZONES_PARENT,
parent_key="_zone_id",
+ # Zones without custom SSL for SaaS enabled get a 400 rather than an empty list.
+ extra_skip_status_codes=(400,),
),
# --- Zone-scoped client-side security ---
"page_shield_scripts": CloudflareEndpointConfig(
@@ -227,6 +237,8 @@ CLOUDFLARE_ENDPOINTS: dict[str, CloudflareEndpointConfig] = {
parent=ACCOUNTS_PARENT,
parent_key="_account_id",
pagination=SINGLE_PAGE,
+ # Accounts without billing-usage entitlement get a 400 rather than an empty list.
+ extra_skip_status_codes=(400,),
),
"billable_usage": CloudflareEndpointConfig(
name="billable_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.py
index d78257d117d9..65c8ae60f038 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
@@ -229,6 +229,29 @@ class TestZoneFanout:
with pytest.raises(requests.HTTPError):
_rows(cloudflare_source("token", "dns_records", team_id=1, job_id="j"))
+ @pytest.mark.parametrize(
+ ("endpoint", "status_code"),
+ [("rate_limits", 410), ("custom_certificates", 400)],
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_skips_zone_missing_plan_feature_and_continues(self, MockSession, endpoint, status_code) -> None:
+ # Cloudflare returns a non-403/404 error when a zone's plan doesn't include a
+ # feature (e.g. legacy rate limiting is 410 Gone, custom certs are 400) rather
+ # than an empty list — one such zone must not abort the whole stream.
+ session = MockSession.return_value
+ _wire(
+ session,
+ [
+ _response([{"id": "z1"}, {"id": "z2"}], total_pages=1),
+ _error_response(status_code),
+ _response([{"id": "r2"}], total_pages=1),
+ ],
+ )
+
+ rows = _rows(cloudflare_source("token", endpoint, team_id=1, job_id="j"))
+
+ assert [(r["id"], r["_zone_id"]) for r in rows] == [("r2", "z2")]
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_zone_without_id_is_skipped(self, MockSession) -> None:
session = MockSession.return_value
@@ -328,6 +351,24 @@ class TestAccountFanout:
assert [(r["id"], r["_account_id"]) for r in rows] == [("n2", "a2")]
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_skips_account_missing_billing_usage_entitlement_and_continues(self, MockSession) -> None:
+ # Accounts without billing-usage entitlement get a 400 rather than an empty
+ # list — one such account must not abort the whole stream.
+ session = MockSession.return_value
+ _wire(
+ session,
+ [
+ _response([{"id": "a1"}, {"id": "a2"}], total_pages=1),
+ _error_response(400),
+ _response([{"ts": 1}], total_pages=1),
+ ],
+ )
+
+ rows = _rows(cloudflare_source("token", "billing_usage", team_id=1, job_id="j"))
+
+ assert [(r["ts"], r["_account_id"]) for r in rows] == [(1, "a2")]
+
class TestSinglePageEndpoints:
@pytest.mark.parametrize(