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(clickhouse): treat unresolved sync columns as non-retryable (#105791)

Tom Owersfd907ac2bce2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
index 696f22f422d7..4b4329483b2c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
@@ -339,6 +339,16 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val
# replays the identical failure, so stop and tell the customer to fix the schema.
# We match the stable suffix, not the volatile `<database>.<table>` prefix.
"not found or has no columns": "We couldn't find this table in your ClickHouse database — it may have been dropped or renamed. If you were syncing a materialized view, sync it by its own name rather than its internal `.inner_id.<uuid>` table (those names change whenever the view is recreated). Remove or re-point this table in your source, then resync.",
+ # UNKNOWN_IDENTIFIER (code 47): a column our extraction query references no longer
+ # resolves against the table at query time, even though `system.columns` listed it at
+ # discovery time — typically a View whose underlying table had a column renamed or
+ # dropped after the View was created (ClickHouse doesn't keep a View's column list in
+ # sync with the tables it selects from). The query reissues the same column list on
+ # every attempt, so it fails identically forever. We match the numeric code, like the
+ # other `Code: NNN` entries above, rather than the `(UNKNOWN_IDENTIFIER)` name suffix —
+ # that suffix comes from the server's own exception text, but the code itself is the
+ # more fundamental, guaranteed-present signal.
+ "Code: 47": "A column referenced during sync no longer exists in your ClickHouse table (UNKNOWN_IDENTIFIER). This usually means a column was renamed or dropped in the underlying table or view — refresh this table's schema, deselect the missing column, or update the incremental field or row filter that references it, then resync.",
# UNKNOWN_TYPE (code 50) raised while ClickHouse streams our extraction
# query as Arrow: a selected column has a type ClickHouse can't serialize
# to Arrow (e.g. an `AggregateFunction(...)` state column on an aggregating
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
index 6af1c993fe8b..4c9194bfd221 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
@@ -679,6 +679,12 @@ class TestClickHouseSourceNonRetryableErrors:
# view's `.inner_id.<uuid>` inner table whose UUID changed when the view was recreated.
"Table soax_stage..inner_id.8c612ff0-b72c-4b20-8ea5-405ed002c2f6 not found or has no columns",
"Table default.some_dropped_table not found or has no columns",
+ # UNKNOWN_IDENTIFIER (code 47) — a column that resolved during discovery no longer
+ # exists at query time, e.g. a View whose underlying table had a column renamed.
+ "Received ClickHouse exception, code: 47, server response: Code: 47. DB::Exception: "
+ "Unknown expression identifier `foo` in scope SELECT `foo`, bar FROM "
+ "(SELECT * FROM some_db.some_view). Maybe you meant: ['bar']. (UNKNOWN_IDENTIFIER) "
+ "(for url http://host:8123)",
# UNKNOWN_TYPE (code 50) — a column type ClickHouse can't serialize to Arrow,
# e.g. an AggregateFunction state column on an aggregating materialized view.
"Received ClickHouse exception, code: 50 (for url https://host:8443)\n Code: 50. "