: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 permission-denied errors as non-retryable (#63753)
Tom Owers037493c3df83
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex b004fe2ecc7a..a2ac3d597521 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -200,7 +200,19 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"TemporaryFileSizeExceedsLimitException": None,"Name or service not known": None,"Network is unreachable": None,+ # `InsufficientPrivilege` is the psycopg exception class name. It only appears once+ # Temporal wraps the activity failure (`ApplicationError` stringifies as+ # "InsufficientPrivilege: ..."), so it matches at the workflow layer but NOT in the+ # activity-level check, where `error_msg = str(e)` is the raw psycopg message —+ # PostgreSQL's SQLSTATE 42501 text "permission denied for table/view/... <name>".+ # Match that message substring so the role-lacks-SELECT case is caught at both layers+ # and we stop retrying instead of re-reading into the same denial every attempt."InsufficientPrivilege": None,+ "permission denied for": (+ "PostHog's database role isn't allowed to read one or more of the tables you selected to sync "+ '(PostgreSQL reported "permission denied"). Grant the connecting role SELECT on those tables '+ "(for example: GRANT SELECT ON <table> TO <role>), then re-enable the sync."+ ),"Connection refused": None,"No route to host": None,"password authentication failed connection": None,diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex 33d088cb8787..ebe72196be07 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -204,6 +204,29 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Exhausted recovery-conflict error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)) — no class name.+ "permission denied for table brand",+ "permission denied for view posthog_areas",+ "permission denied for materialized view posthog_notifications",+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ "InsufficientPrivilege: permission denied for table brand",+ ],+ )+ def test_permission_denied_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"Permission-denied error should be non-retryable: {error_msg}"++ def test_permission_denied_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = "permission denied for table brand"+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Permission-denied error should surface an actionable message"+ assert "SELECT" in friendly[0]+@pytest.mark.parametrize("error_msg",[