: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(flags): tolerate redis errors in hypercache expiry tracking check (#118226)
posthog[bot]a461c3619d88
diff --git a/posthog/storage/hypercache_verifier.py b/posthog/storage/hypercache_verifier.pyindex bd677454bfef..23eae0a4937f 100644--- a/posthog/storage/hypercache_verifier.py+++ b/posthog/storage/hypercache_verifier.py@@ -334,8 +334,19 @@ def _verify_and_fix_batch(logger.warning("Batch cache read failed, falling back to individual lookups", error=str(e))cache_batch_data = {}- # Batch-check expiry tracking- expiry_status = batch_check_expiry_tracking(teams, config)+ # Batch-check expiry tracking. An empty result skips expiry fixes for this batch,+ # so a failed read does not mark every team as missing from the expiry set.+ try:+ expiry_status = batch_check_expiry_tracking(teams, config)+ except SoftTimeLimitExceeded:+ raise+ except Exception as e:+ logger.warning(+ "Batch expiry tracking check failed, skipping expiry fixes for this batch",+ error_type=type(e).__name__,+ error=str(e),+ )+ expiry_status = {}# Batch-check which teams should skip fixes (e.g., grace period for recently updated flags)# This is done once per batch to avoid N+1 queriesdiff --git a/posthog/storage/test/test_hypercache_verifier.py b/posthog/storage/test/test_hypercache_verifier.pyindex e129b8770f9f..66bfd21ef507 100644--- a/posthog/storage/test/test_hypercache_verifier.py+++ b/posthog/storage/test/test_hypercache_verifier.py@@ -886,6 +886,41 @@ class TestVerifyAndFixBatch(BaseTest):assert result.total == 1assert result.errors == 0 # Should not count as error, just fallback+ def test_expiry_tracking_timeout_skips_expiry_fixes_without_aborting_batch(self):+ mock_config = MagicMock()+ mock_config.should_skip_write = None+ mock_config.get_primary_writer_fn = None+ mock_config.get_team_ids_to_skip_fix_fn = None+ mock_config.hypercache.batch_load_fn = None+ mock_config.hypercache.batch_get_from_cache.return_value = {}+ mock_config.hypercache.get_cache_identifier.side_effect = lambda t: str(t.id)+ mock_config.update_fn.return_value = True+ other_team = Team.objects.create(organization=self.organization, name="other")+ statuses = {self.team.id: "match", other_team.id: "miss"}++ result = VerificationResult()++ def verify_fn(team, db_batch_data, cache_batch_data):+ return {"status": statuses[team.id], "issue": None}++ with patch(+ "posthog.storage.hypercache_verifier.batch_check_expiry_tracking",+ side_effect=redis.exceptions.TimeoutError("Timeout reading from socket"),+ ):+ _verify_and_fix_batch(+ teams=[self.team, other_team],+ config=mock_config,+ verify_team_fn=verify_fn,+ cache_type="test_cache",+ result=result,+ )++ assert result.total == 2+ assert result.errors == 0+ assert result.expiry_missing_fixed == 0+ assert result.cache_miss_fixed == 1+ mock_config.update_fn.assert_called_once_with(other_team)+def test_get_team_ids_to_skip_fix_fn_skips_mismatch_fix(self):"""A mismatch on a skip-listed (recently updated) team is left for the in-flightasync rebuild. (A miss is the exception — see test_grace_period_repair_miss_is_config_gated.)"""