: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): stop capturing customer input parse errors on runs (#118883)
posthog[bot]99433efd6e17
diff --git a/products/endpoints/backend/logic/execution.py b/products/endpoints/backend/logic/execution.pyindex 9152ffce9f24..36c500609f73 100644--- a/products/endpoints/backend/logic/execution.py+++ b/products/endpoints/backend/logic/execution.py@@ -139,6 +139,16 @@ def _is_query_guardrail_error(error: BaseException) -> bool:return isinstance(error, _QUERY_GUARDRAIL_ERRORS)+# ClickHouse cannot parse a value the customer sent (e.g. a bad date variable). execute() returns a 400.+_CUSTOMER_INPUT_ERROR_CODES = frozenset(+ {"cannot_parse_date", "cannot_parse_datetime", "cannot_parse_number", "decimal_overflow"}+)+++def _is_customer_input_error(error: BaseException) -> bool:+ return isinstance(error, ExposedCHQueryError) and error.code_name in _CUSTOMER_INPUT_ERROR_CODES++# Connection loss outside SQLSTATE class 08 (connection_exception)._CONNECTION_LOSS_SQLSTATES = frozenset({@@ -899,8 +909,8 @@ class EndpointExecutionService(PydanticModelMixin):return resultexcept Exception as e:- # Guardrail errors are customer-caused, not faults: skip capture and let execute() classify them.- if _is_query_guardrail_error(e):+ # Guardrail and input errors are customer-caused, not faults: skip capture and let execute() classify them.+ if _is_query_guardrail_error(e) or _is_customer_input_error(e):raiselogger.exception("Materialized endpoint execution failed",@@ -1009,8 +1019,8 @@ class EndpointExecutionService(PydanticModelMixin):except Exception as e:self.handle_column_ch_error(e)- # Guardrail errors are customer-caused, not faults: skip capture and let execute() classify them.- if _is_query_guardrail_error(e):+ # Guardrail and input errors are customer-caused, not faults: skip capture and let execute() classify them.+ if _is_query_guardrail_error(e) or _is_customer_input_error(e):raiselogger.exception("Inline endpoint execution failed",diff --git a/products/endpoints/backend/tests/test_endpoint_execution.py b/products/endpoints/backend/tests/test_endpoint_execution.pyindex f690185d776e..68da7015754c 100644--- a/products/endpoints/backend/tests/test_endpoint_execution.py+++ b/products/endpoints/backend/tests/test_endpoint_execution.py@@ -8,6 +8,7 @@ from django.db import InterfaceError, OperationalErrorfrom django.utils import timezoneimport psycopg+from clickhouse_driver.errors import ServerExceptionfrom parameterized import parameterizedfrom prometheus_client import REGISTRYfrom rest_framework import status@@ -21,7 +22,7 @@ from posthog.hogql.errors import ExposedHogQLErrorfrom posthog.clickhouse.client.connection import Workloadfrom posthog.clickhouse.client.limit import ConcurrencyLimitExceededfrom posthog.clickhouse.query_tagging import get_query_tags-from posthog.errors import CHQueryErrorNoCommonType+from posthog.errors import CHQueryErrorNoCommonType, wrap_clickhouse_query_errorfrom posthog.exceptions import APIQueriesBudgetExceeded, ClickHouseAtCapacityfrom products.data_modeling.backend.facade.models import DataModelingJob, DataWarehouseSavedQuery@@ -273,6 +274,36 @@ class TestEndpointExecution(ClickhouseTestMixin, APIBaseTest):},)+ @parameterized.expand(+ [+ ("cannot_parse_datetime", 41, False),+ ("cannot_parse_number", 72, False),+ ("no_common_type", 386, True),+ ]+ )+ def test_customer_input_errors_skip_error_tracking(self, _name: str, code: int, expect_capture: bool):+ endpoint = create_endpoint_with_version(+ name=f"{_name}_capture",+ team=self.team,+ query={"kind": "HogQLQuery", "query": "SELECT count() FROM events"},+ created_by=self.user,+ is_active=True,+ )+ error = wrap_clickhouse_query_error(ServerException("DB::Exception: bad value", code=code))++ with (+ mock.patch("products.endpoints.backend.logic.execution.process_query_model", side_effect=error),+ mock.patch("products.endpoints.backend.logic.execution._emit_endpoint_failure_signal") as mock_signal,+ 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/", {}, format="json"+ )++ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)+ self.assertEqual(mock_capture.called, expect_capture)+ self.assertEqual(mock_signal.called, expect_capture)+def test_capacity_error_preserves_retry_after(self):endpoint = create_endpoint_with_version(name="at_capacity",