: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 reporting data-warehouse Redis blips as bugs (#102333)
Tom Owers3126d2316036
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.pyindex b896abbab9b3..a6f549e52d14 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, NoReturn, Optionalfrom django.db import InterfaceError, InternalError, OperationalErrorfrom django.db.models import Prefetch+import redis.exceptions as redis_exceptionsfrom jsonpath_ng.exceptions import JSONPathErrorfrom requests.exceptions import HTTPErrorfrom structlog.contextvars import bind_contextvars@@ -726,7 +727,8 @@ async def _handle_import_error(by type, since it's already a ``NonReportableError`` subclass and every REST-based source hitsthat condition already. A transient object-store hiccup talking to our own data-warehousebucket is re-raised as ``NonReportableError`` the same way, as is a Django- ``OperationalError``/``InterfaceError`` (a connection-pool blip against our own app DB).+ ``OperationalError``/``InterfaceError`` (a connection-pool blip against our own app DB) and a+ ``redis.exceptions.ConnectionError``/``TimeoutError`` (a blip against our own DATA_WAREHOUSE_REDIS).Everything else is logged as an exception and re-raised so Temporal retries it as usual."""@@ -867,6 +869,17 @@ async def _handle_import_error(await logger.adebug("Transient object-store error - re-raising for Temporal retry")raise NonReportableError(error_msg) from error+ # DATA_WAREHOUSE_REDIS backs resumable-source checkpoints, row tracking, and sync locks — it's+ # PostHog's own instance, never anything a customer's source touches. A connectivity blip there+ # (unreachable, refusing connections while restarting) clears on its own once the instance is+ # reachable again, so it shouldn't disable the schema or page anyone. Narrowed to+ # Connection/TimeoutError rather than the broader RedisError so a real command-level defect+ # (ResponseError) still reaches error tracking.+ if isinstance(error, redis_exceptions.ConnectionError | redis_exceptions.TimeoutError):+ await logger.awarning(error_msg)+ await logger.adebug("Transient data-warehouse Redis error - re-raising for Temporal retry")+ raise NonReportableError(error_msg) from error+# A Django OperationalError/InterfaceError/InternalError here comes from a lookup against# PostHog's own app DB (e.g. resolving a team or CustomPropertySource for the person-property# staging hook) — every source that talks to a customer's own database (Postgres, MySQL,diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.pyindex a53a22bc47c9..7efaea3cfaad 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py@@ -10,6 +10,7 @@ from unittest import mockfrom django.db import InterfaceError, InternalError, OperationalError+import redis.exceptions as redis_exceptionsfrom jsonpath_ng.exceptions import JsonPathParserErrorfrom parameterized import parameterizedfrom requests.exceptions import HTTPError, ProxyError@@ -626,6 +627,66 @@ async def test_transient_object_store_error_reraised_as_non_reportable():logger.aexception.assert_not_awaited()+ [+ (+ "connection_error",+ redis_exceptions.ConnectionError,+ "Error 111 connecting to localhost:6379. Connection refused.",+ ),+ ("timeout_error", redis_exceptions.TimeoutError, "Timeout connecting to server"),+ ]+)+async def test_data_warehouse_redis_error_reraised_as_non_reportable(+ _name: str, error_cls: type[Exception], message: str+):+ # ResumableSourceManager._get_redis (and row tracking, sync locks) talk to PostHog's own+ # DATA_WAREHOUSE_REDIS instance, never anything a customer's source touches. Left unclassified,+ # a connection blip there escapes the activity as a raw redis exception, spending the whole retry+ # budget as a captured error-tracking issue instead of the benign, self-recovering blip it is.+ error = error_cls(message)+ source = mock.MagicMock(spec=SimpleSource)+ source.get_non_retryable_errors.return_value = {}+ source.get_retryable_errors.return_value = set()++ logger = mock.MagicMock()+ logger.awarning = mock.AsyncMock()+ logger.aexception = mock.AsyncMock()+ logger.adebug = mock.AsyncMock()++ with mock.patch.object(module.SourceRegistry, "get_source", return_value=source):+ with pytest.raises(NonReportableError) as exc_info:+ await module._handle_import_error(mock.MagicMock(), logger, error)++ assert exc_info.value.__cause__ is error+ assert str(exc_info.value) == message+ logger.awarning.assert_awaited_once()+ logger.aexception.assert_not_awaited()+++async def test_redis_response_error_is_still_reported():+ # ResponseError (e.g. a malformed command) is a real defect, not a connectivity blip — it must+ # keep reaching error tracking rather than being swept into the same bucket as ConnectionError.+ error = redis_exceptions.ResponseError("wrong number of arguments")+ source = mock.MagicMock(spec=SimpleSource)+ source.get_non_retryable_errors.return_value = {}+ source.get_retryable_errors.return_value = set()++ logger = mock.MagicMock()+ logger.awarning = mock.AsyncMock()+ logger.aexception = mock.AsyncMock()+ logger.adebug = mock.AsyncMock()++ with mock.patch.object(module.SourceRegistry, "get_source", return_value=source):+ with pytest.raises(redis_exceptions.ResponseError) as exc_info:+ await module._handle_import_error(mock.MagicMock(), logger, error)++ assert exc_info.value is error+ logger.aexception.assert_awaited_once()++@pytest.mark.asyncioasync def test_schema_column_type_changed_routes_through_handler_without_source_opt_in():# SchemaColumnTypeChangedException is raised in shared pipeline code when incoming data can't be