: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): stop retrying saml_connections 422s from unsupported accounts (#78776)
Tom Owersfb4f4fd26482
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/source.pyindex ee67f2a02add..41e5a1207961 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clerk/source.py@@ -108,6 +108,12 @@ The secret key starts with `sk_live_`.# Clerk answers 410 for endpoints it has removed. Schema discovery retires the table# within a few hours, so this only covers runs that start in between."410 Client Error: Gone for url: https://api.clerk.com": "Clerk removed this endpoint from its API, so this table can't sync any more. Turn off syncing for this table.",+ # Clerk's own API spec documents only 402/403/422 as possible error responses for this+ # (deprecated) list endpoint — no successful, well-formed request should ever hit this,+ # so a 422 here means SAML connections (Enterprise SSO) aren't available on this Clerk+ # instance. Scoped to this path, not all of api.clerk.com, since 422 elsewhere can mean+ # a genuinely bad request that's worth investigating rather than an account limitation.+ "422 Client Error: Unprocessable Entity for url: https://api.clerk.com/v1/saml_connections": "SAML connections (Enterprise SSO) aren't available on your Clerk plan or instance. Turn off syncing for this table, or enable SAML connections in your Clerk dashboard.",**{reason: reason for reason in RETIRED_ENDPOINTS.values()},}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 06d3e3e536e1..524ccc2cacf5 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@@ -38,6 +38,7 @@ class TestClerkSource:["401 Client Error: Unauthorized for url: https://api.clerk.com","403 Client Error: Forbidden for url: https://api.clerk.com",+ "422 Client Error: Unprocessable Entity for url: https://api.clerk.com/v1/saml_connections",],)def test_non_retryable_errors_includes_clerk_key(self, expected_key):@@ -45,10 +46,16 @@ class TestClerkSource:assert expected_key in errors- def test_non_retryable_errors_matches_observed_error_message(self):- # Matches the full error string seen in production for the `users` endpoint.- observed_error = "401 Client Error: Unauthorized for url: https://api.clerk.com/v1/users?limit=100"-+ @pytest.mark.parametrize(+ "observed_error",+ [+ # `users` endpoint, invalid/revoked secret key.+ "401 Client Error: Unauthorized for url: https://api.clerk.com/v1/users?limit=100",+ # `saml_connections` endpoint, SAML/Enterprise SSO not available on the account's plan.+ "422 Client Error: Unprocessable Entity for url: https://api.clerk.com/v1/saml_connections?limit=100",+ ],+ )+ def test_non_retryable_errors_matches_observed_error_message(self, observed_error):non_retryable_errors = self.source.get_non_retryable_errors()assert any(key in observed_error for key in non_retryable_errors)@@ -64,6 +71,16 @@ class TestClerkSource:assert not any(key in other_vendor_error for key in non_retryable_errors)+ def test_non_retryable_errors_does_not_match_422_on_other_clerk_endpoints(self):+ # A 422 from a different endpoint is a genuinely bad request worth investigating, not an+ # account limitation — the match must stay scoped to `saml_connections`.+ other_endpoint_error = (+ "422 Client Error: Unprocessable Entity for url: https://api.clerk.com/v1/users?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)+def test_get_schemas(self):schemas = self.source.get_schemas(self.config, self.team_id)