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(data-imports): stop _safe_expose_ch_error crashing on errors without .message (#73563)

Tom Owersfeac6562a0d9
diff --git a/products/warehouse_sources/backend/models/table.py b/products/warehouse_sources/backend/models/table.py
index 16e2359117bc..3bab09051b3a 100644
--- a/products/warehouse_sources/backend/models/table.py
+++ b/products/warehouse_sources/backend/models/table.py
@@ -31,7 +31,6 @@ from posthog.hogql.escape_sql import escape_clickhouse_identifier, escape_param_
from posthog.clickhouse.client import sync_execute
from posthog.clickhouse.query_tagging import Feature, Product, tag_queries
from posthog.errors import CORRUPTED_PARQUET_METADATA_MESSAGE, wrap_clickhouse_query_error
-from posthog.exceptions import ClickHouseAtCapacity
from posthog.exceptions_capture import capture_exception
from posthog.models.utils import CreatedMetaFields, DeletedMetaFields, UpdatedMetaFields, UUIDTModel, sane_repr
from posthog.schema_enums import DatabaseSerializedFieldType
@@ -911,10 +910,12 @@ class DataWarehouseTable(CreatedMetaFields, UpdatedMetaFields, UUIDTModel, Delet
raw_message = err.message if isinstance(err, ClickHouseServerException) else str(err)
err = wrap_clickhouse_query_error(err)
- # Capacity errors are transient — surface them so the caller can retry. Check this
- # before the message matching below, since ClickHouseAtCapacity is an APIException
- # and has no `.message` attribute.
- if isinstance(err, ClickHouseAtCapacity):
+ # Only ClickHouse ServerException-derived errors carry a `.message`. Everything else —
+ # transient connection/read errors (e.g. an EOFError from a dropped ClickHouse socket) and
+ # already-translated APIExceptions like ClickHouseAtCapacity — has no `.message`, so re-raise
+ # it untouched. Masking these as a storage-bucket misconfiguration would hide a retryable
+ # error (or an already user-safe one) behind a misleading user-facing message.
+ if not hasattr(err, "message"):
raise err
for key, value in ExtractErrors.items():
diff --git a/products/warehouse_sources/backend/tests/test_table.py b/products/warehouse_sources/backend/tests/test_table.py
index 77e5675cad66..ccfac1b19ad9 100644
--- a/products/warehouse_sources/backend/tests/test_table.py
+++ b/products/warehouse_sources/backend/tests/test_table.py
@@ -98,6 +98,19 @@ class TestSafeExposeChError:
with pytest.raises(ClickHouseAtCapacity):
DataWarehouseTable()._safe_expose_ch_error(ServerException("busy", code=code))
+ # A transient connection/read error (e.g. an EOFError from a dropped ClickHouse socket) is not
+ # a ServerException, so wrap_clickhouse_query_error returns it untouched and it has no `.message`.
+ # It must be re-raised as-is, not masked as a storage-bucket misconfiguration, which would hide
+ # a retryable error from Temporal.
+ @pytest.mark.parametrize(
+ "err",
+ [EOFError("Unexpected EOF while reading bytes"), ConnectionResetError("Connection reset by peer")],
+ )
+ def test_transient_errors_without_message_are_reraised_untouched(self, err: Exception) -> None:
+ with pytest.raises(type(err)) as exc_info:
+ DataWarehouseTable()._safe_expose_ch_error(err)
+ assert exc_info.value is err
+
class TestRunChdbQuery:
def test_hung_query_is_killed_and_raises_instead_of_blocking(self) -> None: