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 missing source table as non-retryable (#64076)

Tom Owersfa29460f808f
diff --git a/posthog/temporal/data_imports/sources/clickhouse/source.py b/posthog/temporal/data_imports/sources/clickhouse/source.py
index b5bb22646e16..4c077879fe29 100644
--- a/posthog/temporal/data_imports/sources/clickhouse/source.py
+++ b/posthog/temporal/data_imports/sources/clickhouse/source.py
@@ -181,6 +181,14 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val
# an existing column in place, so retrying won't help — the table must be reset and
# fully re-synced to adopt the new type.
"Source column type changed": "A column's type changed in your source database (for example an integer column was widened to bigint) and no longer fits the type we stored. We can't widen an existing column in place — please reset and fully re-sync this table to adopt the new type.",
+ # Raised from `_get_table` when `system.columns` returns no columns for the
+ # configured table — the table no longer exists in the source database at sync
+ # time. It was dropped or renamed, or (commonly) the schema points at a
+ # materialized view's auto-generated `.inner_id.<uuid>` inner table whose UUID
+ # changed when the view was recreated. Either way the table is gone and retrying
+ # 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.",
}
def get_schemas(
diff --git a/posthog/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/posthog/temporal/data_imports/sources/clickhouse/test_clickhouse.py
index 75c310794987..cd0af949a01b 100644
--- a/posthog/temporal/data_imports/sources/clickhouse/test_clickhouse.py
+++ b/posthog/temporal/data_imports/sources/clickhouse/test_clickhouse.py
@@ -531,6 +531,10 @@ class TestClickHouseSourceNonRetryableErrors:
# MEMORY_LIMIT_EXCEEDED (code 241) — per-query `max_memory_usage` budget
"Code: 241. DB::Exception: Query memory limit exceeded: would use 3.73 GiB "
"(attempt to allocate chunk of 4.60 MiB), maximum: 3.73 GiB. (MEMORY_LIMIT_EXCEEDED)",
+ # Source table no longer exists at sync time — dropped/renamed, or a materialized
+ # 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",
],
)
def test_permanent_errors_are_non_retryable(self, source, error_msg):