Skip to content

: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.

fix(postgres): stop capturing unsupported statement_timeout as an error (#70310)

Tom Owers1c1d6e01e67b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py
index d7e1bbf2b7de..13d14b2b9307 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/postgres.py
@@ -1065,6 +1065,21 @@ def _is_unsupported_function_error(error: Exception, function_name: str) -> bool
return any(marker in message for marker in ("does not exist", "unknown function", "not found", "no function"))
+def _is_unsupported_statement_timeout_error(error: Exception) -> bool:
+ """True when the engine rejects setting `statement_timeout` as an unsupported feature.
+
+ The best-effort `SET statement_timeout` guarding these metadata scans is a Postgres-only
+ convenience. Some Postgres-wire-compatible engines (CrateDB, Materialize, and similar
+ analytical/streaming proxies) accept the connection but expose a limited GUC set, raising
+ `FeatureNotSupported` — `setting configuration parameter "statement_timeout" not supported`.
+ That's an expected engine limitation, not a bug, so callers degrade quietly rather than
+ flooding error tracking (mirrors `_is_unsupported_function_error`). A genuine timeout
+ cancellation reads `canceling statement due to statement timeout`, so it can't match here.
+ """
+ message = str(error).lower()
+ return "statement_timeout" in message and "not supported" in message
+
+
def _rls_active_from_conn(
connection: psycopg.Connection,
schema: str | None,
@@ -1139,6 +1154,7 @@ def _rls_active_from_conn(
and not connection.broken
and not isinstance(e, psycopg.errors.InFailedSqlTransaction)
and not _is_unsupported_function_error(e, "row_security_active")
+ and not _is_unsupported_statement_timeout_error(e)
):
capture_exception(e)
return {}
@@ -1195,7 +1211,12 @@ def _xmin_capable_tables_from_conn(
# Best-effort like the PK/RLS/index lookups it runs alongside: losing the `supports_xmin`
# hint just hides the option for this listing. A non-Postgres engine may lack `relkind`
# semantics entirely, so degrade quietly.
- if not connection.closed and not connection.broken and not isinstance(e, psycopg.errors.InFailedSqlTransaction):
+ if (
+ not connection.closed
+ and not connection.broken
+ and not isinstance(e, psycopg.errors.InFailedSqlTransaction)
+ and not _is_unsupported_statement_timeout_error(e)
+ ):
structlog.get_logger().warning("Failed to detect xmin-capable tables for Postgres schemas", exc_info=e)
return set()
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.py
index 1217e8df6036..0abfa0b35d55 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
@@ -98,6 +98,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.p
_is_partitioned_table,
_is_read_replica,
_is_unsupported_function_error,
+ _is_unsupported_statement_timeout_error,
_next_recovery_conflict_chunk_size,
_normalize_function_names,
_pk_uniqueness_probe_timeout_error,
@@ -6406,6 +6407,25 @@ class TestIsUnsupportedFunctionError:
assert _is_unsupported_function_error(error, "row_security_active") is expected
+class TestIsUnsupportedStatementTimeoutError:
+ @pytest.mark.parametrize(
+ "error,expected",
+ [
+ (
+ psycopg.errors.FeatureNotSupported('setting configuration parameter "statement_timeout" not supported'),
+ True,
+ ),
+ # A wire-compatible engine may surface it as a generic error rather than FeatureNotSupported.
+ (Exception('setting configuration parameter "statement_timeout" not supported'), True),
+ # A genuine timeout cancellation must stay captured/retryable — it isn't an engine limitation.
+ (psycopg.errors.QueryCanceled("canceling statement due to statement timeout"), False),
+ (Exception("connection reset by peer"), False),
+ ],
+ )
+ def test_recognises_unsupported_statement_timeout(self, error, expected):
+ assert _is_unsupported_statement_timeout_error(error) is expected
+
+
class TestRlsActiveFromConnErrorHandling:
@staticmethod
def _conn_raising(exc: Exception):
@@ -6426,6 +6446,20 @@ class TestRlsActiveFromConnErrorHandling:
assert result == {}
capture_mock.assert_not_called()
+ def test_unsupported_statement_timeout_error_is_not_captured(self):
+ # A Postgres-wire engine that rejects the best-effort `SET statement_timeout` (CrateDB,
+ # Materialize, etc.) is an expected shape: degrade to no RLS warnings without flooding
+ # error tracking.
+ conn = self._conn_raising(
+ psycopg.errors.FeatureNotSupported('setting configuration parameter "statement_timeout" not supported')
+ )
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.postgres.postgres.capture_exception"
+ ) as capture_mock:
+ result = _rls_active_from_conn(cast(Any, conn), "public", ["t"])
+ assert result == {}
+ capture_mock.assert_not_called()
+
def test_unexpected_error_is_still_captured(self):
conn = self._conn_raising(Exception("connection reset by peer"))
with patch(