: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(cohorts): handle a null code_name when parsing calculation errors (#117644)
posthog[bot]33fe09506d35
diff --git a/products/cohorts/backend/models/test/test_util.py b/products/cohorts/backend/models/test/test_util.pyindex 4ecf1b47747e..27055e237e34 100644--- a/products/cohorts/backend/models/test/test_util.py+++ b/products/cohorts/backend/models/test/test_util.py@@ -18,6 +18,7 @@ from rest_framework.exceptions import ValidationError as DRFValidationErrorfrom posthog.hogql.hogql import HogQLContextfrom posthog.clickhouse.client import sync_execute+from posthog.errors import CHQueryErrorS3Errorfrom posthog.exceptions import (ClickHouseAtCapacity,ClickHouseEstimatedQueryExecutionTimeTooLong,@@ -1275,6 +1276,7 @@ class TestParseErrorCode(BaseTest):("clickhouse_timeout", "ClickHouseTimeoutError", CohortErrorCode.TIMEOUT),("clickhouse_type", "ClickHouseTypeError", CohortErrorCode.INCOMPATIBLE_TYPES),("generic_exception", "Exception", CohortErrorCode.UNKNOWN),+ ("clickhouse_null_code_name", "CHQueryErrorS3Error", CohortErrorCode.UNKNOWN),])def test_parse_error_code(self, _name: str, exception_type: str, expected_code: str):@@ -1297,6 +1299,9 @@ class TestParseErrorCode(BaseTest):if exception_type in simple_exceptions:return simple_exceptions[exception_type]("test")+ if exception_type == "CHQueryErrorS3Error":+ return CHQueryErrorS3Error("test", code=499)+if exception_type == "EstimatedQueryExecutionTimeTooLong":return ClickHouseEstimatedQueryExecutionTimeTooLong()diff --git a/products/cohorts/backend/models/util.py b/products/cohorts/backend/models/util.pyindex ff2550421626..034dd5348bce 100644--- a/products/cohorts/backend/models/util.py+++ b/products/cohorts/backend/models/util.py@@ -158,7 +158,7 @@ def parse_error_code(e: Exception) -> CohortErrorCode:case PydanticValidationError() | ValidationError():return CohortErrorCode.VALIDATION_ERROR- code_name = getattr(e, "code_name", "").lower()+ code_name = (getattr(e, "code_name", None) or "").lower()if code_name in _CLICKHOUSE_ERROR_MAPPING:return _CLICKHOUSE_ERROR_MAPPING[code_name]