: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(snowflake): treat broken-source SQL compilation errors as non-retryable (#63743)
Tom Owers883cda62cb6f
diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex e2d4546ccdfc..e0486461d1a7 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -923,6 +923,9 @@ class TestServerCursorStatementTimeout:def __init__(self):self.autocommit = Falseself.closed = False+ # Real psycopg connections expose `broken`; the setup path probes it via+ # `_raise_if_setup_connection_broken`, so the fake must carry it too.+ self.broken = Falseself.adapters = mock.Mock()def cursor(self, *args, **kwargs):diff --git a/posthog/temporal/data_imports/sources/snowflake/source.py b/posthog/temporal/data_imports/sources/snowflake/source.pyindex ba52a72be0c7..196eb14ea789 100644--- a/posthog/temporal/data_imports/sources/snowflake/source.py+++ b/posthog/temporal/data_imports/sources/snowflake/source.py@@ -219,6 +219,10 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):# narrower type. Delta Lake can't widen 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.",+ # Snowflake SQL compilation error 002057: a view's declared column list no longer+ # matches the columns its query produces, so the view itself fails to compile. This is+ # a broken object on the source side that retrying can't repair.+ "but view query produces": "A Snowflake view in your source is invalid — the columns it declares no longer match the columns its query returns. Please recreate the view in Snowflake so the two agree, then resync.",}def validate_credentials(diff --git a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.pyindex 482b6ab34715..1ee16a2e7a12 100644--- a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py+++ b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py@@ -715,6 +715,21 @@ class TestSnowflakeSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Missing/unauthorized object error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ "but view query produces",+ # The real shape from production: the view name and column counts vary, but the+ # "but view query produces" substring is stable.+ "002057 (42601): 01c5120c-0009-a976-0001-40ae0960c0a6: SQL compilation error: View definition for "+ "'DB.PUBLIC.SOME_VIEW' declared 42 column(s), but view query produces 43 column(s).",+ ],+ )+ def test_broken_view_column_count_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"Broken-view error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[