: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 non-integer incremental cursor error as non-retryable (#63781)
Tom Owers35e40f18fd45
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex b4bfd9faaf8a..171346a3fae5 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -254,6 +254,15 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# 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 by the source Postgres when the incremental query compares an integer column+ # against a non-integer cursor value, e.g. `WHERE "id" > '1.5'`. `_build_query` renders+ # the stored `incremental_field_last_value` as a SQL literal, so a fractional/non-integer+ # cursor produces `InvalidTextRepresentation: invalid input syntax for type integer`.+ # This is deterministic — every retry re-runs the identical failing query — and signals a+ # type mismatch between the incremental field and its data. The volatile offending value+ # (`: "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.",}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 c3a7b669c32d..dd98f41065f3 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -251,6 +251,18 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Widened integer column error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ 'invalid input syntax for type integer: "1.5"',+ 'InvalidTextRepresentation: invalid input syntax for type integer: "1.5"',+ ],+ )+ def test_non_integer_incremental_cursor_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"Non-integer incremental cursor error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[