: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(errors): return 400 for CANNOT_CONVERT_TYPE query errors (#87240)
posthog[bot]9befe47935f6
diff --git a/posthog/errors.py b/posthog/errors.pyindex b3d21eeb8e59..b2bd563a4738 100644--- a/posthog/errors.py+++ b/posthog/errors.py@@ -416,9 +416,14 @@ CLICKHOUSE_ERROR_CODE_LOOKUP: dict[int, ErrorCodeMeta] = {68: ErrorCodeMeta("CANNOT_GET_SIZE_OF_FIELD"),# Fixed message: the raw CH text formats a per-row value (e.g. geoToH3 resolution) into the error.69: ErrorCodeMeta("ARGUMENT_OUT_OF_BOUND", user_safe="An argument is out of bounds."),- # 70/72 stay internal: their CH messages embed the failing data value (see code 6 note).- 70: ErrorCodeMeta("CANNOT_CONVERT_TYPE", category=QueryErrorCategory.USER_ERROR),+ # Fixed message: the raw CH text embeds the failing data value (see code 6 note), so a fixed+ # string keeps that value out of the response while still returning a 400 for the bad query.+ 70: ErrorCodeMeta(+ "CANNOT_CONVERT_TYPE",+ user_safe="Cannot convert one type to another in the query. Check the types in your comparisons and IN clauses.",+ ),71: ErrorCodeMeta("CANNOT_WRITE_AFTER_END_OF_BUFFER"),+ # 72 stays internal: the CH message embeds the failing data value (see code 6 note).72: ErrorCodeMeta("CANNOT_PARSE_NUMBER", category=QueryErrorCategory.USER_ERROR),73: ErrorCodeMeta("UNKNOWN_FORMAT"),74: ErrorCodeMeta("CANNOT_READ_FROM_FILE_DESCRIPTOR"),diff --git a/posthog/test/test_errors.py b/posthog/test/test_errors.pyindex 0e3fe90610e0..1643f2457db0 100644--- a/posthog/test/test_errors.py+++ b/posthog/test/test_errors.py@@ -44,6 +44,11 @@ class TestWrapClickhouseQueryError:# fixed user_safe string. The assertion guards against a revert to user_safe=True, which# would pass the raw ClickHouse text (and the source value) straight through.(69, "ARGUMENT_OUT_OF_BOUND", "An argument is out of bounds."),+ (+ 70,+ "CANNOT_CONVERT_TYPE",+ "Cannot convert one type to another in the query. Check the types in your comparisons and IN clauses.",+ ),(407, "DECIMAL_OVERFLOW", "Decimal overflow while executing query."),])@@ -65,7 +70,6 @@ class TestWrapClickhouseQueryError:# These parse/convert codes embed the failing data value in the CH message, so they stay# internal to avoid leaking source values on public shared insights.(6, "CANNOT_PARSE_TEXT"),- (70, "CANNOT_CONVERT_TYPE"),(72, "CANNOT_PARSE_NUMBER"),(675, "CANNOT_PARSE_IPV4"),(676, "CANNOT_PARSE_IPV6"),