: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(data-warehouse): skip over-long column names in semantic enrichment (#66641)
Tom Owers8643dc610bd3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/enrich_table_semantics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/enrich_table_semantics.pyindex d352b6eccffe..aa146c9edfdc 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/enrich_table_semantics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/enrich_table_semantics.py@@ -344,18 +344,34 @@ def _get_business_context(team: Team) -> str:# Never worth enriching: they carry no user-facing meaning and each one would burn an LLM column slot._INTERNAL_COLUMNS = frozenset({"_dlt_id", "_dlt_load_id", "_ph_debug", PARTITION_KEY})+# An annotation is keyed by `column_name`, a varchar(400). A column whose name doesn't fit can't be+# stored or surfaced, so skip it rather than letting the insert raise (DataError) and crash the whole+# table's enrichment into a Temporal retry loop.+_MAX_COLUMN_NAME_LENGTH: int = WarehouseColumnAnnotation._meta.get_field("column_name").max_length or 400-def _columns_from_table(table: DataWarehouseTable) -> list[dict[str, Any]]:++def _columns_from_table(table: DataWarehouseTable, log: Any = logger) -> list[dict[str, Any]]:"""Source-agnostic `[{name, data_type, is_nullable}]` from `DataWarehouseTable.columns`.`columns` is populated after every sync for every source type (unlike SQL-only `schema_metadata`),keyed by column name with a ClickHouse type. Handles both the dict shape (`{"clickhouse": ...}`)- and the legacy plain-string shape. Internal plumbing columns are skipped.+ and the legacy plain-string shape. Internal plumbing columns, and any whose name exceeds the+ annotation key length, are skipped."""result: list[dict[str, Any]] = []for name, definition in (table.columns or {}).items():if name in _INTERNAL_COLUMNS:continue+ if len(name) > _MAX_COLUMN_NAME_LENGTH:+ # Surface the drop — otherwise the column silently vanishes from enrichment with no trace,+ # the same opacity that made the original DataError crash hard to diagnose.+ log.warning(+ "warehouse_enrichment.column_name_too_long",+ column_name_prefix=name[:64],+ column_name_length=len(name),+ max_column_name_length=_MAX_COLUMN_NAME_LENGTH,+ )+ continueif isinstance(definition, dict):clickhouse_type = definition.get("clickhouse") or definition.get("hogql") or ""else:@@ -412,7 +428,7 @@ def enrich_table_semantics_sync(team_id: int, schema_id: uuid.UUID) -> dict[str,# Columns + types come from `table.columns`, populated for every source type after sync — so this# enriches REST sources (Stripe, Hubspot, …) as well as SQL ones. Foreign keys remain SQL-only.- columns = [column for column in _columns_from_table(table) if column.get("name")]+ columns = [column for column in _columns_from_table(table, log) if column.get("name")]event_props["columns_total"] = len(columns)if not columns:emit_completed("skipped", reason="no_columns")diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_enrich_table_semantics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_enrich_table_semantics.pyindex f68fe0f48f3a..4f4db19a3cdb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_enrich_table_semantics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_enrich_table_semantics.py@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.workflow_activitieenrich_table_semantics as enrich,)from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.enrich_table_semantics import (+ _MAX_COLUMN_NAME_LENGTH,MAX_BUSINESS_CONTEXT_CHARS,MAX_PROMPT_CHARS,EnrichTableSemanticsInputs,@@ -318,6 +319,14 @@ class TestColumnsFromTable:names = {column["name"] for column in _columns_from_table(table)}assert names == {"id", "amount"}+ def test_skips_columns_whose_name_exceeds_annotation_key_length(self):+ # A column name longer than the annotation's varchar key can't be stored — including it would+ # crash the whole table's enrichment with a DataError. It must be dropped, not enriched.+ long_name = "a" * (_MAX_COLUMN_NAME_LENGTH + 1)+ table = DataWarehouseTable(columns={"id": {"clickhouse": "String"}, long_name: {"clickhouse": "String"}})+ names = {column["name"] for column in _columns_from_table(table)}+ assert names == {"id"}+class TestExtractJsonObject:@pytest.mark.parametrize(