: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): stop capturing activity cancellation as an RLS probe error (#119163)
Tom Owers0ec4915e6e05
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.pyindex 0a8b4670aab3..6ec0ad0bfbd8 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@@ -1418,6 +1418,18 @@ def _is_pooler_login_cooldown_error(error: BaseException) -> bool:return "server login has been failing" in message and "server_login_retry" in message+def _is_activity_cancelled(error: BaseException) -> bool:+ """True when `error` is Temporal cancelling the activity, not a genuine query failure.++ Temporal can inject a `temporalio.exceptions.CancelledError` (an `Exception` subclass) into+ whatever statement is running when the activity is cancelled or hits its+ `start_to_close_timeout` — here, typically the catalog query inside a best-effort metadata+ probe. Match on the type name rather than importing temporalio into this module, mirroring+ `sync_lock._is_cancellation`.+ """+ return type(error).__name__ == "CancelledError"++def _rls_active_from_conn(connection: psycopg.Connection,schema: str | None,@@ -1501,6 +1513,9 @@ def _rls_active_from_conn(# `_xmin_capable_tables_from_conn`, which already degrades quietly for it). A pooler# login-retry cooldown (e.g. a duckgres-backed source's own metadata store momentarily# can't log in) is the same self-healing shape — see `_is_pooler_login_cooldown_error`.+ # Temporal cancelling the activity mid-probe (user cancelled the sync, or the activity hit+ # its `start_to_close_timeout`) is the same shape too: the sync is ending regardless of+ # what this best-effort lookup returns, so there's nothing to fix here.# Still capture genuinely unexpected failures.if (not connection.closed@@ -1510,6 +1525,7 @@ def _rls_active_from_conn(and not _is_unsupported_statement_timeout_error(e)and not _is_statement_timeout_error(e)and not _is_pooler_login_cooldown_error(e)+ and not _is_activity_cancelled(e)):capture_exception(e)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.pyindex d1e1dc3354e6..77d4f0f43dba 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@@ -10008,6 +10008,23 @@ class TestRlsActiveFromConnErrorHandling:assert result == {}capture_mock.assert_not_called()+ def test_activity_cancelled_error_is_not_captured(self):+ # Temporal injects a `temporalio.exceptions.CancelledError` into whatever statement is+ # running when the activity is cancelled (user cancels the sync, or it hits its+ # start_to_close_timeout). That's expected, not a bug in this best-effort lookup — don't+ # flood error tracking with it. Matched by type name, like `sync_lock._is_cancellation`,+ # so the fake class here doesn't need to depend on temporalio.+ class CancelledError(Exception):+ pass++ conn = self._conn_raising(CancelledError("Cancelled"))+ 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_failed_sql_transaction_is_not_captured(self):# This lookup shares a connection with earlier best-effort metadata queries (PK + index# discovery). When one of those fails on a non-Postgres engine (e.g. Redshift) its exception