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(errors): mark ambiguous-identifier query errors user-safe (#78421)

Thiago Salvatoreea59eee2ee4c
diff --git a/posthog/errors.py b/posthog/errors.py
index b0f84200ad91..c1901a2b04c9 100644
--- a/posthog/errors.py
+++ b/posthog/errors.py
@@ -519,9 +519,7 @@ CLICKHOUSE_ERROR_CODE_LOOKUP: dict[int, ErrorCodeMeta] = {
203: ErrorCodeMeta("NO_FREE_CONNECTION", category=QueryErrorCategory.RATE_LIMITED),
204: ErrorCodeMeta("CANNOT_FSYNC"),
206: ErrorCodeMeta("ALIAS_REQUIRED"),
- 207: ErrorCodeMeta(
- "AMBIGUOUS_IDENTIFIER", category=QueryErrorCategory.USER_ERROR
- ), # identifier resolves to multiple columns or aliases
+ 207: ErrorCodeMeta("AMBIGUOUS_IDENTIFIER", user_safe=True), # identifier resolves to multiple columns or aliases
208: ErrorCodeMeta("EMPTY_NESTED_TABLE"),
209: ErrorCodeMeta("SOCKET_TIMEOUT"),
210: ErrorCodeMeta("NETWORK_ERROR"),
@@ -637,7 +635,7 @@ CLICKHOUSE_ERROR_CODE_LOOKUP: dict[int, ErrorCodeMeta] = {
346: ErrorCodeMeta("CANNOT_CONVERT_CHARSET"),
347: ErrorCodeMeta("CANNOT_LOAD_CONFIG"),
349: ErrorCodeMeta("CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN", user_safe=True),
- 352: ErrorCodeMeta("AMBIGUOUS_COLUMN_NAME", category=QueryErrorCategory.USER_ERROR),
+ 352: ErrorCodeMeta("AMBIGUOUS_COLUMN_NAME", user_safe=True),
353: ErrorCodeMeta("INDEX_OF_POSITIONAL_ARGUMENT_IS_OUT_OF_RANGE", user_safe=True),
354: ErrorCodeMeta("ZLIB_INFLATE_FAILED"),
355: ErrorCodeMeta("ZLIB_DEFLATE_FAILED"),
diff --git a/posthog/test/test_errors.py b/posthog/test/test_errors.py
new file mode 100644
index 000000000000..40d777ef0856
--- /dev/null
+++ b/posthog/test/test_errors.py
@@ -0,0 +1,37 @@
+from clickhouse_driver.errors import ServerException
+from parameterized import parameterized
+
+from posthog.errors import (
+ ExposedCHQueryError,
+ InternalCHQueryError,
+ QueryErrorCategory,
+ look_up_clickhouse_error_code_meta,
+ wrap_clickhouse_query_error,
+)
+
+
+class TestWrapClickhouseQueryError:
+ @parameterized.expand(
+ [
+ # Ambiguous-identifier query errors are the user's malformed HogQL, not a server fault,
+ # so they must wrap as ExposedCHQueryError and stay out of error tracking.
+ (207, "AMBIGUOUS_IDENTIFIER"),
+ (352, "AMBIGUOUS_COLUMN_NAME"),
+ ]
+ )
+ def test_ambiguous_identifier_codes_wrap_as_exposed_error(self, code: int, name: str) -> None:
+ err = ServerException(f"DB::Exception: {name}", code=code)
+
+ wrapped = wrap_clickhouse_query_error(err)
+
+ assert isinstance(wrapped, ExposedCHQueryError)
+ assert look_up_clickhouse_error_code_meta(err).get_category() == QueryErrorCategory.USER_ERROR
+
+ def test_unmapped_internal_code_stays_internal(self) -> None:
+ # NETWORK_ERROR (210) is a genuine server-side fault and must not be exposed.
+ err = ServerException("DB::Exception: NETWORK_ERROR", code=210)
+
+ wrapped = wrap_clickhouse_query_error(err)
+
+ assert isinstance(wrapped, InternalCHQueryError)
+ assert not isinstance(wrapped, ExposedCHQueryError)