: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(hogql): classify wrong-arg-count errors as user query errors (#70920)
posthog[bot]64cd449ae0ea
diff --git a/posthog/errors.py b/posthog/errors.pyindex 5fee0fe43e91..769a69d51a63 100644--- a/posthog/errors.py+++ b/posthog/errors.py@@ -253,7 +253,7 @@ class CHQueryErrorIllegalAggregation(ExposedCHQueryError):pass-class CHQueryErrorNumberOfArgumentsDoesntMatch(InternalCHQueryError):+class CHQueryErrorNumberOfArgumentsDoesntMatch(ExposedCHQueryError):pass@@ -350,15 +350,15 @@ CLICKHOUSE_ERROR_CODE_LOOKUP: dict[int, ErrorCodeMeta] = {28: ErrorCodeMeta("CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER"),32: ErrorCodeMeta("ATTEMPT_TO_READ_AFTER_EOF"),33: ErrorCodeMeta("CANNOT_READ_ALL_DATA"),- 34: ErrorCodeMeta("TOO_MANY_ARGUMENTS_FOR_FUNCTION", category=QueryErrorCategory.USER_ERROR),- 35: ErrorCodeMeta("TOO_FEW_ARGUMENTS_FOR_FUNCTION", category=QueryErrorCategory.USER_ERROR),+ 34: ErrorCodeMeta("TOO_MANY_ARGUMENTS_FOR_FUNCTION", user_safe=True),+ 35: ErrorCodeMeta("TOO_FEW_ARGUMENTS_FOR_FUNCTION", user_safe=True),36: ErrorCodeMeta("BAD_ARGUMENTS", user_safe=True),37: ErrorCodeMeta("UNKNOWN_ELEMENT_IN_AST"),38: ErrorCodeMeta("CANNOT_PARSE_DATE", user_safe=True),39: ErrorCodeMeta("TOO_LARGE_SIZE_COMPRESSED"),40: ErrorCodeMeta("CHECKSUM_DOESNT_MATCH"),41: ErrorCodeMeta("CANNOT_PARSE_DATETIME", user_safe=True),- 42: ErrorCodeMeta("NUMBER_OF_ARGUMENTS_DOESNT_MATCH", category=QueryErrorCategory.USER_ERROR),+ 42: ErrorCodeMeta("NUMBER_OF_ARGUMENTS_DOESNT_MATCH", user_safe=True),43: ErrorCodeMeta("ILLEGAL_TYPE_OF_ARGUMENT", user_safe=True),44: ErrorCodeMeta("ILLEGAL_COLUMN", category=QueryErrorCategory.USER_ERRORdiff --git a/posthog/hogql/test/test_log_query_settings.py b/posthog/hogql/test/test_log_query_settings.pyindex 489ac907f426..deea635f6af1 100644--- a/posthog/hogql/test/test_log_query_settings.py+++ b/posthog/hogql/test/test_log_query_settings.py@@ -1,13 +1,21 @@import pytestfrom posthog.test.base import APIBaseTest, ClickhouseTestMixin+from unittest import TestCasefrom clickhouse_driver.errors import ServerException+from parameterized import parameterizedfrom posthog.hogql.constants import HogQLGlobalSettingsfrom posthog.hogql.errors import QueryErrorfrom posthog.hogql.query import HogQLQueryExecutor-from posthog.errors import CHQueryErrorTooManyBytes, ExposedCHQueryError, wrap_clickhouse_query_error+from posthog.errors import (+ CHQueryErrorTooManyBytes,+ ExposedCHQueryError,+ QueryErrorCategory,+ classify_query_error,+ wrap_clickhouse_query_error,+)class TestLogQuerySettings(ClickhouseTestMixin, APIBaseTest):@@ -117,3 +125,21 @@ class TestTooManyBytesError(ClickhouseTestMixin, APIBaseTest):)wrapped = wrap_clickhouse_query_error(server_error)assert getattr(wrapped, "code_name", None) == "too_many_bytes"+++class TestArgumentCountErrorsAreUserFacing(TestCase):+ """Wrong-function-arg-count errors are user query mistakes, not internal bugs, so they must+ surface as exposed 4xx errors and be classified USER_ERROR rather than captured as internals."""++ @parameterized.expand(+ [+ (34, "TOO_MANY_ARGUMENTS_FOR_FUNCTION"),+ (35, "TOO_FEW_ARGUMENTS_FOR_FUNCTION"),+ (42, "NUMBER_OF_ARGUMENTS_DOESNT_MATCH"),+ ]+ )+ def test_argument_count_error_is_exposed_and_user_error(self, code: int, name: str) -> None:+ server_error = ServerException(f"DB::Exception: Function minus {name.lower()}.", code=code)+ wrapped = wrap_clickhouse_query_error(server_error)+ assert isinstance(wrapped, ExposedCHQueryError)+ assert classify_query_error(wrapped) == QueryErrorCategory.USER_ERROR