: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(data-imports): treat WorkOS 422 responses as non-retryable (#64611)
Tom Owers62b0d43538c6
diff --git a/posthog/temporal/data_imports/sources/workos/source.py b/posthog/temporal/data_imports/sources/workos/source.pyindex 55b7d7490e84..791cf36cd426 100644--- a/posthog/temporal/data_imports/sources/workos/source.py+++ b/posthog/temporal/data_imports/sources/workos/source.py@@ -89,6 +89,10 @@ The key starts with `sk_`.return {"401 Client Error: Unauthorized for url: https://api.workos.com": "Your WorkOS API key is invalid or has been revoked. Please update the key in your WorkOS dashboard and reconnect.","403 Client Error: Forbidden for url: https://api.workos.com": "Your WorkOS API key does not have permission to access this endpoint. Please check the key's scopes in your WorkOS dashboard.",+ # WorkOS returns 422 for a syntactically valid list request it can't fulfil for this+ # account — e.g. the Directory Sync endpoints (directory_users/directory_groups) when+ # Directory Sync isn't provisioned. It's deterministic, so retrying never resolves it.+ "422 Client Error: Unprocessable Entity for url: https://api.workos.com": "WorkOS could not process the request for one of the endpoints being synced. This usually means the data isn't available for your WorkOS account (for example, Directory Sync isn't configured). Please check your WorkOS configuration and the endpoints you're syncing, then reconnect.",}def validate_credentials(diff --git a/posthog/temporal/data_imports/sources/workos/tests/test_workos_source.py b/posthog/temporal/data_imports/sources/workos/tests/test_workos_source.pyindex 97673f49eee4..2308c03b3075 100644--- a/posthog/temporal/data_imports/sources/workos/tests/test_workos_source.py+++ b/posthog/temporal/data_imports/sources/workos/tests/test_workos_source.py@@ -40,14 +40,21 @@ class TestWorkOSSource:["401 Client Error: Unauthorized for url: https://api.workos.com","403 Client Error: Forbidden for url: https://api.workos.com",+ "422 Client Error: Unprocessable Entity for url: https://api.workos.com",],)def test_non_retryable_errors_includes_workos_key(self, expected_key):errors = self.source.get_non_retryable_errors()assert expected_key in errors- def test_non_retryable_errors_matches_observed_error_message(self):- observed_error = "401 Client Error: Unauthorized for url: https://api.workos.com/organizations?limit=100"+ @pytest.mark.parametrize(+ "observed_error",+ [+ "401 Client Error: Unauthorized for url: https://api.workos.com/organizations?limit=100",+ "422 Client Error: Unprocessable Entity for url: https://api.workos.com/directory_users?limit=100&order=desc",+ ],+ )+ 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)