: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(endpoints): count validation errors as user errors (#128160)
Jovan Sakoviccf9b4391019e
diff --git a/products/endpoints/backend/logic/execution.py b/products/endpoints/backend/logic/execution.pyindex 7a816ddf2ac5..865a48576a6e 100644--- a/products/endpoints/backend/logic/execution.py+++ b/products/endpoints/backend/logic/execution.py@@ -145,6 +145,8 @@ _CUSTOMER_INPUT_ERROR_CODES = frozenset(def _is_customer_input_error(error: BaseException) -> bool:+ if isinstance(error, ValidationError):+ return Truereturn isinstance(error, ExposedCHQueryError) and error.code_name in _CUSTOMER_INPUT_ERROR_CODES@@ -642,6 +644,10 @@ class EndpointExecutionService(PydanticModelMixin):endpoint_name=endpoint.name,)raise ValidationError("Query resolution failed: unable to resolve table or field references.")+ except ValidationError:+ execution_status = "user_error"+ error_label = "ValidationError"+ raiseexcept ConcurrencyLimitExceeded:record_endpoint_rate_limited(team_id=self.team.pk,diff --git a/products/endpoints/backend/tests/test_endpoint_execution.py b/products/endpoints/backend/tests/test_endpoint_execution.pyindex 59abe304e28a..7e6394e0f3b4 100644--- a/products/endpoints/backend/tests/test_endpoint_execution.py+++ b/products/endpoints/backend/tests/test_endpoint_execution.py@@ -2819,6 +2819,40 @@ class TestEndpointExecution(ClickhouseTestMixin, APIBaseTest):)self.assertEqual(inline_after - inline_before, 1.0)+ def test_paginating_union_query_counts_as_user_error(self):+ from prometheus_client import REGISTRY++ endpoint = create_endpoint_with_version(+ name="union_limit_test",+ team=self.team,+ query={"kind": "HogQLQuery", "query": "SELECT 1 AS x UNION ALL SELECT 2 AS x"},+ created_by=self.user,+ is_active=True,+ )+ labels = {"execution_type": "inline", "query_kind": "hogql"}+ user_error_before = (+ REGISTRY.get_sample_value("posthog_endpoint_execution_total", {**labels, "status": "user_error"}) or 0.0+ )+ error_before = (+ REGISTRY.get_sample_value("posthog_endpoint_execution_total", {**labels, "status": "error"}) or 0.0+ )++ with mock.patch("products.endpoints.backend.logic.execution.capture_exception") as mock_capture:+ response = self.client.post(+ f"/api/environments/{self.team.id}/endpoints/{endpoint.name}/run/", {"limit": 10}, format="json"+ )++ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.json())+ user_error_after = (+ REGISTRY.get_sample_value("posthog_endpoint_execution_total", {**labels, "status": "user_error"}) or 0.0+ )+ error_after = (+ REGISTRY.get_sample_value("posthog_endpoint_execution_total", {**labels, "status": "error"}) or 0.0+ )+ self.assertEqual(user_error_after - user_error_before, 1.0)+ self.assertEqual(error_after - error_before, 0.0)+ mock_capture.assert_not_called()+def test_emit_failure_signal_reaches_workflow_boundary(self):"""The failure-signal plumbing must make it to the Temporal boundary when theorg/source gates allow it — anything raising before that is a plumbing bug."""