: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-warehouse): treat read-only-transaction blips as transient in repartition (#89041)
Tom Owers50b60ba2f13a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.pyindex a7139b464927..25348286ed02 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py@@ -17,9 +17,10 @@ import datetime as dtimport dataclassesfrom typing import Any-from django.db import InterfaceError, OperationalError, close_old_connections+from django.db import InterfaceError, InternalError, OperationalError, close_old_connectionsfrom django.utils import timezone+import psycopg.errorsfrom asgiref.sync import async_to_syncfrom structlog.contextvars import bind_contextvarsfrom structlog.types import FilteringBoundLogger@@ -135,6 +136,14 @@ def _rewrite_deadline(activity_started: float) -> float | None:def _is_transient_infra_error(error: Exception) -> bool:if isinstance(error, OperationalError | InterfaceError):return True+ # A primary-DB failover briefly routes one of the rewrite's own writes (checkpoint, swap marker,+ # scheme persist) onto a connection that has become a read-only standby: Postgres raises+ # ReadOnlySqlTransaction (SQLSTATE 25006), which psycopg classifies under InternalError rather than+ # OperationalError, so it needs its own check. Matched on the cause, not a bare InternalError+ # isinstance, so real corruption errors sharing the base class are still reported. Mirrors the same+ # classification in delta.errors.is_transient_maintenance_error.+ if isinstance(error, InternalError) and isinstance(error.__cause__, psycopg.errors.ReadOnlySqlTransaction):+ return Truemessage = str(error).lower()return any(snippet in message for snippet in _TRANSIENT_ERROR_SNIPPETS)diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.pyindex f6d0fb898548..ebaa23a9badb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_repartition_table.py@@ -5,8 +5,9 @@ import contextvarsimport pytestfrom unittest.mock import AsyncMock, MagicMock, patch-from django.db import InterfaceError, OperationalError+from django.db import InterfaceError, InternalError, OperationalError+import psycopg.errorsfrom parameterized import parameterizedfrom posthog.exceptions_capture import ambient_exception_properties@@ -45,6 +46,14 @@ PENDING_TARGET = {}+def _read_only_transaction_error() -> InternalError:+ # Mirrors how Django's DatabaseErrorWrapper re-raises a psycopg error: the driver exception+ # (carrying SQLSTATE 25006) becomes __cause__.+ error = InternalError("cannot execute UPDATE in a read-only transaction")+ error.__cause__ = psycopg.errors.ReadOnlySqlTransaction("cannot execute UPDATE in a read-only transaction")+ return error++def _schema(*,name: str,@@ -544,6 +553,10 @@ class TestTransientObjectStoreFailure:),),("interface_error", InterfaceError("connection already closed")),+ # A primary-DB failover routes a rewrite write onto a read-only standby mid-run: psycopg+ # raises ReadOnlySqlTransaction (25006), wrapped by Django as InternalError. It clears on+ # the next sync, so it must stand down like the other infra blips, not burn an attempt.+ ("read_only_transaction_failover", _read_only_transaction_error()),])@patch(f"{MODULE}.capture_exception")