: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(data-imports): stop retrying postgres syncs on a custom access-check RAISE (#120383)
Tom Owers22f4182c1973
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 562b5f540565..8416da4b83ba 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@@ -1572,6 +1572,22 @@ class PostgresSource("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."),+ # A view or computed column in the customer's own schema calls a PL/pgSQL function that+ # enforces its own access check and raises a custom RAISE EXCEPTION when it finds no+ # user context — commonly a Supabase helper keyed off auth.uid(), which Supabase's+ # PostgREST layer populates per-request but a direct database connection like ours never+ # sets. We only ever run `SELECT ... FROM <relation>`; the check lives in the customer's+ # own function and runs on every row, so it fails identically on every retry. Match the+ # stable guard message and exclude the volatile CONTEXT line naming the function and+ # line number.+ "Access denied: No user ID provided": (+ "A view or column you're syncing calls a function in your database that checks for "+ 'a signed-in user and rejects the read when none is present ("Access denied: No '+ 'user ID provided"). This usually means the function depends on request-scoped auth '+ "context (for example Supabase's auth.uid()) that a direct database connection like "+ "PostHog's never has. Update the function to allow the connecting role through, or "+ "remove the affected view or column 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 ce6f0b58d352..9fff7ac3c29e 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@@ -1797,6 +1797,28 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Division-by-zero error should surface an actionable message"assert "divides by" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)) — a view/column's+ # own PL/pgSQL function raising a custom access-check error during our read.+ "Access denied: No user ID provided\nCONTEXT: PL/pgSQL function reject_anonymous_reads(uuid) line 9 at RAISE",+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ "RaiseException: Access denied: No user ID provided",+ ],+ )+ def test_custom_function_access_denied_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"Custom function access-denied error should be non-retryable: {error_msg}"++ def test_custom_function_access_denied_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = "Access denied: No user ID provided"+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Custom function access-denied error should surface an actionable message"+ assert "auth.uid()" in friendly[0]+@pytest.mark.parametrize("error_msg",[