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(clerk): treat a missing machines list as a feature that's off (#102869)

Tom Owers0730aeed623a
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.py
index 11ac8835e522..85ec0cf41fa6 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
@@ -114,7 +114,15 @@ CLERK_ENDPOINTS: dict[str, ClerkEndpointConfig] = {
# give. Skip zero rows instead of failing the schema every run.
gated_feature="OAuth applications",
),
- "machines": ClerkEndpointConfig(name="machines", path="/machines", is_wrapped_response=True),
+ "machines": ClerkEndpointConfig(
+ name="machines",
+ path="/machines",
+ is_wrapped_response=True,
+ # Clerk answers 404 resource_not_found for the machines list on instances without machine
+ # (M2M) authentication — the same feature-off signal the domains and OAuth applications
+ # endpoints give. Skip zero rows instead of failing the schema every run.
+ gated_feature="Machine (M2M) authentication",
+ ),
# /api_keys and /m2m_tokens cap `limit` at 100 rather than 500.
"api_keys": ClerkEndpointConfig(name="api_keys", path="/api_keys", is_wrapped_response=True),
"m2m_tokens": ClerkEndpointConfig(
@@ -123,6 +131,9 @@ CLERK_ENDPOINTS: dict[str, ClerkEndpointConfig] = {
is_wrapped_response=True,
data_key="m2m_tokens",
fan_out=ClerkFanOut(parent="machines", parent_field="id", query_param="subject"),
+ # Fans out over /machines, so the same feature-off 404 surfaces here through the parent
+ # fetch before any token request is sent.
+ gated_feature="Machine (M2M) authentication",
),
"redirect_urls": ClerkEndpointConfig(name="redirect_urls", path="/redirect_urls"),
"jwt_templates": ClerkEndpointConfig(name="jwt_templates", path="/jwt_templates"),
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.py
index 3e6998af0975..567e944725fc 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
@@ -530,6 +530,10 @@ class TestClerkFeatureGatedEndpoints:
("invitations", 404, {"errors": [{"code": "resource_not_found"}]}),
# SMS off: the SMS template list answers the same 404 resource_not_found.
("sms_templates", 404, {"errors": [{"code": "resource_not_found"}]}),
+ # Machine (M2M) auth off: the machines list answers the same 404 resource_not_found.
+ ("machines", 404, {"errors": [{"code": "resource_not_found"}]}),
+ # m2m_tokens fans out over /machines, so it meets the same 404 on its parent fetch.
+ ("m2m_tokens", 404, {"errors": [{"code": "resource_not_found"}]}),
],
)
def test_feature_not_enabled_syncs_no_rows_instead_of_failing(