Skip to content

: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.

fix(data-imports): stop redis errors masking non-retryable import failures (#87412)

Tom Owersbecf3d0f2f4b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
index 3ceb849841f3..0f482128a701 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
@@ -5,6 +5,7 @@ from django.conf import settings
import pyarrow as pa
import posthoganalytics
+from redis import exceptions as redis_exceptions
from structlog.typing import FilteringBoundLogger
from temporalio import activity
@@ -237,10 +238,19 @@ async def handle_non_retryable_error(
raise NonRetryableException() from error
retry_key = build_non_retryable_errors_redis_key(team_id, source_id, run_id)
- attempts = await redis_client.incr(retry_key)
+ try:
+ attempts = await redis_client.incr(retry_key)
+ if attempts <= NON_RETRYABLE_ERROR_RETRY_LIMIT:
+ await redis_client.expire(retry_key, 86400) # Expire after 24 hours
+ except redis_exceptions.RedisError as e:
+ # A successful ping doesn't guarantee later commands still have a Redis to talk to -
+ # treat that the same as a `None` client instead of letting it surface unwrapped and
+ # mask the already-classified `error` behind an ordinary retryable activity failure.
+ capture_exception(e)
+ await logger.adebug(f"Redis became unreachable tracking a non-retryable error. error={error_msg}")
+ raise NonRetryableException() from error
if attempts <= NON_RETRYABLE_ERROR_RETRY_LIMIT:
- await redis_client.expire(retry_key, 86400) # Expire after 24 hours
await logger.adebug(
f"Non-retryable error attempt {attempts}/{NON_RETRYABLE_ERROR_RETRY_LIMIT}, retrying. error={error_msg}"
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
index e50ffae42db1..f35297b49b8b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
@@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
from asgiref.sync import async_to_sync
from parameterized import parameterized
+from redis import exceptions as redis_exceptions
from posthog.temporal.common.errors import NonReportableError
@@ -742,3 +743,30 @@ class TestHandleNonRetryableError:
assert isinstance(exc_info.value, NonReportableError)
assert exc_info.value.__cause__ is original_error
+
+ def test_redis_error_after_successful_ping_fails_fast(self):
+ # A successful ping doesn't guarantee `.incr()` still reaches Redis - if it raises, this
+ # must take the same fast-fail path as a `None` client instead of surfacing unwrapped and
+ # masking the already-classified `error` behind an ordinary retryable activity failure.
+ original_error = ValueError("Ad account owner has NOT granted ads_read permission")
+ redis_client = MagicMock(
+ incr=AsyncMock(side_effect=redis_exceptions.ConnectionError("Connect call failed")),
+ expire=AsyncMock(),
+ )
+
+ @asynccontextmanager
+ async def fake_get_redis():
+ yield redis_client
+
+ with (
+ patch(f"{_EXTRACT_MODULE}._get_redis", fake_get_redis),
+ patch(f"{_EXTRACT_MODULE}.capture_exception") as mock_capture,
+ ):
+ with pytest.raises(NonRetryableException) as exc_info:
+ async_to_sync(handle_non_retryable_error)(
+ 1, "source-1", "run-1", str(original_error), MagicMock(adebug=AsyncMock()), original_error
+ )
+
+ assert isinstance(exc_info.value, NonRetryableException)
+ assert exc_info.value.__cause__ is original_error
+ mock_capture.assert_called_once()