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 (#70309)

Tom Owers4c9e6031ade0
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 f1a1849d647e..09ea852b1a9e 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
@@ -1104,11 +1104,19 @@ def _rls_active_from_conn(
"""
try:
with connection.cursor() as cursor:
- cursor.execute(
- sql.SQL("SET LOCAL statement_timeout = {timeout}").format(
- timeout=sql.Literal(1000 * 30) # 30 secs
+ try:
+ cursor.execute(
+ sql.SQL("SET LOCAL statement_timeout = {timeout}").format(
+ timeout=sql.Literal(1000 * 30) # 30 secs
+ )
)
- )
+ except psycopg.errors.FeatureNotSupported:
+ # Some Postgres-wire-compatible engines (e.g. Aurora DSQL) don't implement setting
+ # statement_timeout. This SET is only a best-effort guard against a runaway catalog
+ # scan, so its rejection is an expected incompatibility — degrade quietly instead of
+ # flooding error tracking. Scoped to this statement so an unrelated FeatureNotSupported
+ # from the catalog queries below still reaches the capture path.
+ return {}
discovered_tables, _qualify_with_schema = _get_discovered_tables(cursor, schema, names)
if not discovered_tables:
return {}
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 3db0b2e68217..2d522e12ec62 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
@@ -6522,6 +6522,37 @@ class TestRlsActiveFromConnErrorHandling:
assert result == {}
capture_mock.assert_not_called()
+ def test_unsupported_statement_timeout_error_is_not_captured(self):
+ # Some Postgres-wire-compatible engines (e.g. Aurora DSQL) reject the `SET LOCAL
+ # statement_timeout` guard this lookup opens with (raising FeatureNotSupported on that first
+ # statement). That's an expected incompatibility, not a bug — degrade quietly instead of
+ # 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_feature_not_supported_after_timeout_guard_is_still_captured(self):
+ # The statement_timeout tolerance is scoped to the SET guard only. A FeatureNotSupported from
+ # a catalog query after it is a genuinely unexpected shape and must still surface, not be
+ # blanket-swallowed.
+ conn = mock.MagicMock()
+ conn.closed = False
+ conn.broken = False
+ cursor = conn.cursor.return_value.__enter__.return_value
+ cursor.execute.side_effect = [None, psycopg.errors.FeatureNotSupported("cannot open cursor on this engine")]
+ 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_called_once()
+
class TestGetRowsInitialConnectRetry:
# Regression: the main server-cursor read path opened its initial connection with a bare