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-warehouse): give actionable copy when file upload column detection fails (#74093)

Tom Owers48a37ecc545a
diff --git a/products/data_warehouse/backend/presentation/views/table.py b/products/data_warehouse/backend/presentation/views/table.py
index 0f2a8a04c6e6..a493e1f6954b 100644
--- a/products/data_warehouse/backend/presentation/views/table.py
+++ b/products/data_warehouse/backend/presentation/views/table.py
@@ -26,6 +26,7 @@ from posthog.tasks.warehouse import validate_data_warehouse_table_columns
from products.data_warehouse.backend.facade.api import get_s3_client
from products.warehouse_sources.backend.facade.api import (
+ FILE_FORMAT_READ_HINTS,
FILE_FORMAT_TO_TABLE_FORMAT,
MAX_FILE_UPLOAD_SIZE_BYTES,
SUPPORTED_FILE_FORMATS,
@@ -675,9 +676,14 @@ class TableViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.M
try:
table.columns = table.get_columns()
except Exception as err:
+ # The raw column-detection failure is a ClickHouse error that's opaque to users, so keep it
+ # in error tracking and hand back plain, format-specific guidance on what to check instead.
+ capture_exception(err)
+ hint = FILE_FORMAT_READ_HINTS.get(file_format, "")
+ message = f"Couldn't read the columns from your file. {hint}".strip()
return response.Response(
status=status.HTTP_400_BAD_REQUEST,
- data={"message": f"Could not read columns from the uploaded file: {err}"},
+ data={"message": message},
)
table.save()
diff --git a/products/data_warehouse/backend/tests/api/test_warehouse_table_file_upload.py b/products/data_warehouse/backend/tests/api/test_warehouse_table_file_upload.py
index 645c7bd90c38..281621ca3bcf 100644
--- a/products/data_warehouse/backend/tests/api/test_warehouse_table_file_upload.py
+++ b/products/data_warehouse/backend/tests/api/test_warehouse_table_file_upload.py
@@ -9,6 +9,7 @@ from django.test import override_settings
from parameterized import parameterized
from rest_framework import status
+from products.warehouse_sources.backend.facade.api import FILE_FORMAT_READ_HINTS
from products.warehouse_sources.backend.models.credential import DataWarehouseCredential
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
from products.warehouse_sources.backend.models.table import DataWarehouseTable
@@ -285,6 +286,36 @@ class TestCreateTableFromUpload(APIBaseTest):
assert "not found" in response.json()["message"]
assert DataWarehouseTable.objects.count() == 0
+ @parameterized.expand(["csv", "json", "parquet"])
+ def test_column_read_failure_returns_format_specific_guidance(self, file_format: str) -> None:
+ # A failed get_columns() raises an opaque ClickHouse error; the endpoint must swallow it and
+ # hand back format-specific guidance instead of leaking the raw exception, and persist nothing.
+ upload_id = self._upload(filename=f"data.{file_format}", file_format=file_format)
+ with (
+ patch(f"{VIEW_MODULE}.get_s3_client", return_value=_FakeS3()),
+ patch(
+ f"{MODEL_MODULE}.DataWarehouseTable.get_columns",
+ side_effect=Exception("DB::Exception: Cannot extract table structure"),
+ ),
+ patch(f"{VIEW_MODULE}.validate_data_warehouse_table_columns.delay"),
+ ):
+ response = self.client.post(
+ f"{self.create_url}?include_columns=false",
+ data={
+ "upload_id": upload_id,
+ "filename": f"data.{file_format}",
+ "file_format": file_format,
+ "table_name": f"data_{file_format}",
+ },
+ format="json",
+ )
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ message = response.json()["message"]
+ assert "DB::Exception" not in message
+ assert FILE_FORMAT_READ_HINTS[file_format] in message
+ assert DataWarehouseTable.objects.count() == 0
+
@override_settings(DATAWAREHOUSE_BUCKET="test-bucket", DATAWAREHOUSE_BUCKET_DOMAIN="warehouse.posthog.test")
class TestWarehouseTableDeleteRemovesHostedFile(APIBaseTest):
diff --git a/products/warehouse_sources/backend/facade/api.py b/products/warehouse_sources/backend/facade/api.py
index 07e41c6874b7..e226cf413dde 100644
--- a/products/warehouse_sources/backend/facade/api.py
+++ b/products/warehouse_sources/backend/facade/api.py
@@ -20,6 +20,7 @@ from uuid import UUID
# Source-agnostic storage contract for user-uploaded files — shared with the upload endpoint.
from products.warehouse_sources.backend.file_uploads import (
+ FILE_FORMAT_READ_HINTS,
FILE_FORMAT_TO_TABLE_FORMAT,
MAX_UPLOAD_SIZE_BYTES as MAX_FILE_UPLOAD_SIZE_BYTES,
SUPPORTED_FILE_FORMATS,
@@ -66,6 +67,7 @@ __all__ = [
"validate_source_prefix",
"validate_warehouse_table_url_pattern",
# file-upload storage contract
+ "FILE_FORMAT_READ_HINTS",
"FILE_FORMAT_TO_TABLE_FORMAT",
"MAX_FILE_UPLOAD_SIZE_BYTES",
"SUPPORTED_FILE_FORMATS",
diff --git a/products/warehouse_sources/backend/file_uploads.py b/products/warehouse_sources/backend/file_uploads.py
index 2351ff2df63d..5711c3f9e7a1 100644
--- a/products/warehouse_sources/backend/file_uploads.py
+++ b/products/warehouse_sources/backend/file_uploads.py
@@ -33,6 +33,15 @@ FILE_FORMAT_TO_TABLE_FORMAT: dict[str, str] = {
FORMAT_PARQUET: "Parquet",
}
+# Per-format guidance shown when column detection fails on create. Each hint names the exact shape
+# the matching read format above expects, since that's what silently trips uploads up: CSV needs a
+# header row, and JSON is read one object per line rather than as a single array.
+FILE_FORMAT_READ_HINTS: dict[str, str] = {
+ FORMAT_CSV: "Make sure it's a comma-separated CSV with a header row and the same number of columns in every row.",
+ FORMAT_JSON: "Make sure it's newline-delimited JSON, with one object per line rather than a single array.",
+ FORMAT_PARQUET: "Make sure it's a valid Parquet file.",
+}
+
# Cap on uploads streamed through the web pod. Larger datasets belong on a self-managed S3/GCS
# source, where PostHog reads the customer's bucket directly instead of hosting the bytes.
MAX_UPLOAD_SIZE_BYTES = 50 * 1024 * 1024