: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): sync zero rows when a Clerk instance has Organizations off (#103445)
Tom Owers9e03a0069995
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/settings.pyindex 85ec0cf41fa6..c3be3a1814cc 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/settings.py@@ -38,9 +38,19 @@ class ClerkEndpointConfig:# Note: Clerk API does not support filtering by updated_at, so only full refresh is supported.CLERK_ENDPOINTS: dict[str, ClerkEndpointConfig] = {"users": ClerkEndpointConfig(name="users", path="/users"),- "organizations": ClerkEndpointConfig(name="organizations", path="/organizations", is_wrapped_response=True),+ # Clerk answers 404 resource_not_found for every instance-wide Organizations list on instances+ # that don't have Organizations switched on — the same feature-off signal the organization+ # invitations list below already carries. A list endpoint returns 200 with an empty array when+ # it simply holds no rows, so a 404 here can't mean a missing record. Skip zero rows instead of+ # failing the schema every run.+ "organizations": ClerkEndpointConfig(+ name="organizations", path="/organizations", is_wrapped_response=True, gated_feature="Organizations"+ ),"organization_memberships": ClerkEndpointConfig(- name="organization_memberships", path="/organization_memberships", is_wrapped_response=True+ name="organization_memberships",+ path="/organization_memberships",+ is_wrapped_response=True,+ gated_feature="Organizations",),"invitations": ClerkEndpointConfig(name="invitations",@@ -66,13 +76,19 @@ CLERK_ENDPOINTS: dict[str, ClerkEndpointConfig] = {gated_feature="Organizations",),"organization_domains": ClerkEndpointConfig(- name="organization_domains", path="/organization_domains", is_wrapped_response=True+ name="organization_domains",+ path="/organization_domains",+ is_wrapped_response=True,+ gated_feature="Organizations",),"organization_roles": ClerkEndpointConfig(- name="organization_roles", path="/organization_roles", is_wrapped_response=True+ name="organization_roles", path="/organization_roles", is_wrapped_response=True, gated_feature="Organizations"),"organization_permissions": ClerkEndpointConfig(- name="organization_permissions", path="/organization_permissions", is_wrapped_response=True+ name="organization_permissions",+ path="/organization_permissions",+ is_wrapped_response=True,+ gated_feature="Organizations",),"role_sets": ClerkEndpointConfig(name="role_sets", path="/role_sets", is_wrapped_response=True),"waitlist_entries": ClerkEndpointConfig(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 567e944725fc..d79890ce4a3e 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@@ -526,6 +526,12 @@ class TestClerkFeatureGatedEndpoints:("domains", 404, {"errors": [{"code": "resource_not_found"}]}),# Organizations off: the invitations list answers the same 404 resource_not_found.("organization_invitations", 404, {"errors": [{"code": "resource_not_found"}]}),+ # Organizations off: every other instance-wide Organizations list answers it too.+ ("organizations", 404, {"errors": [{"code": "resource_not_found"}]}),+ ("organization_memberships", 404, {"errors": [{"code": "resource_not_found"}]}),+ ("organization_domains", 404, {"errors": [{"code": "resource_not_found"}]}),+ ("organization_roles", 404, {"errors": [{"code": "resource_not_found"}]}),+ ("organization_permissions", 404, {"errors": [{"code": "resource_not_found"}]}),# Invitations unavailable: the list answers the same 404 resource_not_found.("invitations", 404, {"errors": [{"code": "resource_not_found"}]}),# SMS off: the SMS template list answers the same 404 resource_not_found.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk_source.pyindex 0352f86f0d58..342236d10b55 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/tests/test_clerk_source.py@@ -70,7 +70,7 @@ class TestClerkSource:def test_non_retryable_errors_does_not_match_404_on_other_clerk_endpoints(self):# A 404 from an endpoint we don't classify may be a genuinely missing record worth# investigating — the matches must stay scoped to the paths where a 404 is deterministic.- other_endpoint_error = "404 Client Error: Not Found for url: https://api.clerk.com/v1/organizations?limit=100"+ other_endpoint_error = "404 Client Error: Not Found for url: https://api.clerk.com/v1/api_keys?limit=100"non_retryable_errors = self.source.get_non_retryable_errors()assert not any(key in other_endpoint_error for key in non_retryable_errors)