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): reset redis client to none after a failed ping (#84210)

Tom Owersd5111c55b370
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 75badbc83e80..41aa93599c6f 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
@@ -60,6 +60,10 @@ async def _get_redis():
await redis.ping()
except Exception as e:
capture_exception(e)
+ # get_async_client only builds a lazy client, so a failed ping means redis is
+ # still unreachable - reset it to None so callers' `if redis_client is None` guard
+ # actually skips the real command instead of raising the same error uncaught.
+ redis = None
yield redis
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 cd73c5890e6e..e50ffae42db1 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
@@ -18,6 +18,7 @@ from products.warehouse_sources.backend.models.oom_event import ExternalDataSche
from products.warehouse_sources.backend.temporal.data_imports.external_data_job import Any_Source_Errors
from products.warehouse_sources.backend.temporal.data_imports.pipelines.common.extract import (
NON_RETRYABLE_ERROR_RETRY_LIMIT,
+ _get_redis,
handle_corrupted_delta_log,
handle_non_retryable_error,
handle_reset_or_full_refresh,
@@ -675,6 +676,30 @@ class TestValidateIncrementalSync:
assert [key for key in Any_Source_Errors if key in message]
+class TestGetRedis:
+ @pytest.mark.asyncio
+ async def test_yields_none_when_ping_fails(self):
+ # `handle_non_retryable_error` only takes its Redis-unreachable fast-fail path when the
+ # yielded client is None; otherwise it calls `.incr()` on the broken client, which raises
+ # the same connection error uncaught instead of failing fast as NonRetryableException.
+ # `get_async_client` only builds a lazy client, so a failed ping is the only signal that
+ # the client is unusable - it must reset the client to None rather than yield it as-is.
+ broken_client = AsyncMock(ping=AsyncMock(side_effect=ConnectionError("Connect call failed")))
+
+ with (
+ patch(f"{_EXTRACT_MODULE}.settings") as mock_settings,
+ patch(f"{_EXTRACT_MODULE}.get_async_client", return_value=broken_client),
+ patch(f"{_EXTRACT_MODULE}.capture_exception") as mock_capture,
+ ):
+ mock_settings.DATA_WAREHOUSE_REDIS_HOST = "localhost"
+ mock_settings.DATA_WAREHOUSE_REDIS_PORT = 6379
+
+ async with _get_redis() as redis_client:
+ assert redis_client is None
+
+ mock_capture.assert_called_once()
+
+
class TestHandleNonRetryableError:
def _fake_get_redis(self, incr_return: int):
redis_client = MagicMock(incr=AsyncMock(return_value=incr_return), expire=AsyncMock())