: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): classify a source-side division by zero as non-retryable (#119980)
Tom Owers8ea8e0e63513
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 c9cd9eefb858..0a9d6cdec8ed 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@@ -1523,6 +1523,18 @@ class PostgresSource("or foreign table that converts text to uuid, so fix the data or the column type, or ""remove the table from the sync. Then re-enable the sync."),+ # Raised (DivisionByZero, SQLSTATE 22012) while Postgres evaluates a row during the main+ # `SELECT ... FROM <relation>` read. We only ever select configured columns and apply the+ # customer's own row filters; the division lives in the relation's own definition — a+ # generated/computed column, or a view that divides by another column or expression that+ # is zero for at least one row. Deterministic against the source data, so every retry+ # re-evaluates the same relation into the same row.+ "division by zero": (+ "A table or view you're syncing has a computed column or definition that divides by "+ 'zero for at least one row (PostgreSQL reported "division by zero"). Guard the '+ "division in that column or view definition (for example with a CASE or NULLIF), or "+ "remove it from the sync, then re-enable the sync."+ ),}def get_retryable_errors(self) -> set[str]:diff --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 dde602fcfc0a..536747951357 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@@ -1712,6 +1712,27 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Unsupported interval-unit error should surface an actionable message"assert "interval" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)).+ "division by zero",+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ "DivisionByZero: division by zero",+ ],+ )+ def test_division_by_zero_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"Division-by-zero error should be non-retryable: {error_msg}"++ def test_division_by_zero_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = "division by zero"+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Division-by-zero error should surface an actionable message"+ assert "divides by" in friendly[0]+@pytest.mark.parametrize("error_msg",[