: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(clerk): recognize Clerk's 404 feature-off signal for gated tables (#87744)
Tom Owers0b198699d60a
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.pyindex 70dd2bba7a66..110050f85e11 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@@ -271,13 +271,18 @@ def validate_credentials(secret_key: str) -> tuple[bool, str | None]:# statuses Clerk returns them under: 402 carries no body code, so the status alone is the signal._FEATURE_DISABLED_CODES = frozenset({"billing_not_enabled", "feature_not_enabled"})+# A gated list endpoint (the Restrictions allow-list and block-list) answers 404 `resource_not_found`+# instead of a 4xx feature code when its feature is off. This check only runs for endpoints that carry+# a `gated_feature`, so a 404 here means the feature is not on rather than a genuinely missing record.+_FEATURE_DISABLED_NOT_FOUND_CODE = "resource_not_found"+def _is_feature_disabled(response: Optional[Response]) -> bool:if response is None:return Falseif response.status_code == 402:return True- if response.status_code not in (400, 403):+ if response.status_code not in (400, 403, 404):return Falsetry:@@ -288,7 +293,10 @@ def _is_feature_disabled(response: Optional[Response]) -> bool:errors = body.get("errors") if isinstance(body, dict) else Noneif not isinstance(errors, list):return False- return any(isinstance(error, dict) and error.get("code") in _FEATURE_DISABLED_CODES for error in errors)+ codes = {error.get("code") for error in errors if isinstance(error, dict)}+ if response.status_code == 404:+ return _FEATURE_DISABLED_NOT_FOUND_CODE in codes+ return bool(codes & _FEATURE_DISABLED_CODES)def _skip_when_feature_disabled(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.pyindex 392d733e461b..d4eaaa916d98 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@@ -518,6 +518,8 @@ class TestClerkFeatureGatedEndpoints:("commerce_plans", 400, {"errors": [{"code": "billing_not_enabled"}]}),("commerce_subscription_items", 400, {"errors": [{"code": "billing_not_enabled"}]}),("commerce_plans", 403, {"errors": [{"code": "feature_not_enabled"}]}),+ # Restrictions off: the allow-list endpoint answers 404 resource_not_found, not a 4xx code.+ ("allowlist_identifiers", 404, {"errors": [{"code": "resource_not_found"}]}),],)def test_feature_not_enabled_syncs_no_rows_instead_of_failing(@@ -534,6 +536,8 @@ class TestClerkFeatureGatedEndpoints:[# A gated endpoint failing for an unrelated reason must still fail the sync.("commerce_plans", 400, {"errors": [{"code": "invalid_request"}]}),+ # A 404 with an unrelated code is a real failure, not the feature-off signal.+ ("allowlist_identifiers", 404, {"errors": [{"code": "invalid_request"}]}),# A table with no feature gate never swallows an error.("users", 402, {"errors": [{"code": "payment_required"}]}),],