: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 missing incremental field as non-retryable (#70704)
Tom Owers99f466c1f6bf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex c591426da97c..80e8481f756e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -372,6 +372,17 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"key for the table in its sync settings, or switch it to full table replication, then ""re-enable the sync."),+ # The schema's sync type wants an incremental cursor (incremental/append) but no+ # incremental field is stored in its config, so `_build_query`/`_build_count_query`+ # raise this before emitting any SQL. The stored config is fixed until the customer+ # changes it, so every retry re-hits the same wall — non-retryable, like the missing+ # primary key above. Reset doesn't clear `incremental_field`, so this isn't a transient+ # reset artifact.+ "incremental_field and incremental_field_type can't be None": (+ "This table is set to sync incrementally but has no incremental field configured, so "+ "PostHog can't build its sync query. Choose an incremental field for the table in its "+ "sync settings, or switch it to full table replication, then re-enable the sync."+ ),"failed: timeout expired": None,# NOTE: "SSL connection has been closed unexpectedly" is intentionally NOT listed here.# It denotes an established SSL connection being dropped on connect or mid-stream (idlediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex 29080ca34b0a..381e43cf8527 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -727,6 +727,29 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Non-integer incremental cursor error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "builder",+ [+ # schema, table_name, should_use_incremental_field, table_type, incremental_field,+ # incremental_field_type, db_incremental_field_last_value+ lambda: _build_query("public", "my_table", True, None, None, None, None),+ # _build_count_query has no `table_type` parameter+ lambda: _build_count_query("public", "my_table", True, None, None, None),+ ],+ )+ def test_missing_incremental_field_is_non_retryable(self, source, builder):+ # Drive the real raise sites so a message change that breaks the classifier key is caught.+ with pytest.raises(ValueError) as exc_info:+ builder()+ error_msg = str(exc_info.value)+ 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"Missing incremental field error should be non-retryable: {error_msg}"++ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Missing incremental field error should surface an actionable message"+ assert "incremental field" in friendly[0]+def test_exhausted_recovery_conflict_retries_are_non_retryable(self, source):error_msg = str(_recovery_conflict_abort_error(10))non_retryable = source.get_non_retryable_errors()