: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(postgres): treat unpopulated materialized view as non-retryable (#63975)
Tom Owersd544019b031b
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex 8330fffb4d38..2099b5309a37 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -270,6 +270,16 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# (`: "1.5"`) is excluded from the match. Coercing the cursor here would change sync# semantics (risk of skipped/duplicated rows), so stop and ask the user to reset."invalid input syntax for type integer": "PostHog tried to resume this table's incremental sync from a non-integer cursor value against an integer incremental field, which your database rejects. This usually means the incremental field's type doesn't match its data. Please reset and fully re-sync this table, or pick a different incremental field.",+ # Raised (ObjectNotInPrerequisiteState, SQLSTATE 55000) when a selected materialized view+ # was created `WITH NO DATA` and never refreshed — every SELECT against it fails until the+ # customer runs `REFRESH MATERIALIZED VIEW`. Deterministic and outside our control, so+ # retrying just re-reads into the same error. Match the stable message fragment and exclude+ # the volatile view name.+ "has not been populated": (+ "One of the materialized views you selected to sync hasn't been populated yet "+ '(PostgreSQL reported "has not been populated"). Run REFRESH MATERIALIZED VIEW on it in '+ "your database so it contains data, then re-enable the sync."+ ),}def reconcile_schema_metadata(diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex 79cb03c24289..2140dd13c3e0 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -320,6 +320,27 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Permission-denied error should surface an actionable message"assert "SELECT" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)).+ 'materialized view "mv_dayplan_blocks" has not been populated\nHINT: Use the REFRESH MATERIALIZED VIEW command.',+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ 'ObjectNotInPrerequisiteState: materialized view "mv_dayplan_blocks" has not been populated',+ ],+ )+ def test_unpopulated_materialized_view_errors_are_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"Unpopulated materialized view error should be non-retryable: {error_msg}"++ def test_unpopulated_materialized_view_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = 'materialized view "mv_dayplan_blocks" has not been populated'+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Unpopulated materialized view error should surface an actionable message"+ assert "REFRESH MATERIALIZED VIEW" in friendly[0]+@pytest.mark.parametrize("error_msg",[