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 reusing an unreachable redis client in row tracking (#82571)

Tom Owers9036d2de2ee1
diff --git a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
index d55b04f6ef25..d594998bd802 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
@@ -45,6 +45,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 not redis: return` 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/tests/test_row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
index e27d7179322e..616400df4adc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
@@ -30,6 +30,29 @@ from products.warehouse_sources.backend.temporal.data_imports.row_tracking impor
)
+class TestRowTrackingRedisUnavailable(BaseTest):
+ @pytest.mark.asyncio
+ async def test_setup_row_tracking_does_not_raise_when_redis_is_unreachable(self):
+ # get_async_client only builds a lazy client - the ping is the first real
+ # connection attempt. If it fails, the client must not be used again, or the
+ # next command (hset) raises the same connection error, this time uncaught.
+ unreachable_client = mock.AsyncMock()
+ unreachable_client.ping.side_effect = redis_exceptions.ConnectionError(
+ "Error connecting to redis:6379. Temporary failure in name resolution."
+ )
+
+ with (
+ mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.row_tracking.get_async_client",
+ return_value=unreachable_client,
+ ),
+ override_settings(DATA_WAREHOUSE_REDIS_HOST="localhost", DATA_WAREHOUSE_REDIS_PORT="6379"),
+ ):
+ await setup_row_tracking(self.team.pk, str(uuid.uuid4()))
+
+ unreachable_client.hset.assert_not_called()
+
+
@pytest.mark.timeout(600)
@mock.patch(
"products.warehouse_sources.backend.temporal.data_imports.row_tracking.database_sync_to_async_pool",