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(workos): build valid directory_groups/directory_users list requests (#62155)

Tom Owers51abcb0c9c4e
diff --git a/posthog/temporal/data_imports/sources/workos/tests/test_workos.py b/posthog/temporal/data_imports/sources/workos/tests/test_workos.py
index 7bf1951d1d72..329391f9c6bc 100644
--- a/posthog/temporal/data_imports/sources/workos/tests/test_workos.py
+++ b/posthog/temporal/data_imports/sources/workos/tests/test_workos.py
@@ -13,6 +13,7 @@ from posthog.temporal.data_imports.sources.workos.settings import ENDPOINTS, WOR
from posthog.temporal.data_imports.sources.workos.workos import (
WorkOSPaginator,
WorkOSResumeConfig,
+ get_resource,
validate_credentials,
workos_source,
)
@@ -137,6 +138,16 @@ class TestWorkOSEndpoints:
# Every endpoint partitions on the immutable created_at field.
assert all(cfg.partition_key == "created_at" for cfg in WORKOS_ENDPOINTS.values())
+ @pytest.mark.parametrize("endpoint", list(ENDPOINTS))
+ def test_resource_request_params_are_valid(self, endpoint: str) -> None:
+ # directory_users and directory_groups reject ``order=asc`` with a 422; every
+ # WorkOS list endpoint accepts ``order=desc`` (the WorkOS SDK default). Guard
+ # against regressing back to the rejected value on any endpoint.
+ endpoint_config = cast(dict[str, Any], get_resource(endpoint)["endpoint"])
+ params = cast(dict[str, Any], endpoint_config["params"])
+ assert params["order"] == "desc"
+ assert params["limit"] == WORKOS_ENDPOINTS[endpoint].page_size
+
@pytest.mark.parametrize("endpoint", list(ENDPOINTS))
def test_source_response_shape(self, endpoint: str) -> None:
manager = MagicMock(spec=ResumableSourceManager)
diff --git a/posthog/temporal/data_imports/sources/workos/workos.py b/posthog/temporal/data_imports/sources/workos/workos.py
index 1f7aaead765a..9377f65bb38f 100644
--- a/posthog/temporal/data_imports/sources/workos/workos.py
+++ b/posthog/temporal/data_imports/sources/workos/workos.py
@@ -98,7 +98,10 @@ def get_resource(name: str) -> EndpointResource:
"params": {
"limit": config.page_size,
# Stable creation-ordered pagination so the cursor walks deterministically.
- "order": "asc",
+ # Must be "desc" (the WorkOS SDK default): the high-volume directory_users
+ # and directory_groups list endpoints reject "order=asc" with a 422, while
+ # "desc" is accepted on every WorkOS list endpoint.
+ "order": "desc",
},
}