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(flags): stop re-raising ClickHouse errors from enriched analytics task (#77435)

posthog[bot]16685943e71d
diff --git a/posthog/tasks/tasks.py b/posthog/tasks/tasks.py
index 76264152497d..02f3ac1efc62 100644
--- a/posthog/tasks/tasks.py
+++ b/posthog/tasks/tasks.py
@@ -23,7 +23,7 @@ from posthog.hogql.constants import LimitContext
from posthog.clickhouse.client.limit import ConcurrencyLimitExceeded, limit_concurrency
from posthog.clickhouse.query_tagging import Feature, Product, get_query_tags, tag_queries
from posthog.cloud_utils import is_cloud
-from posthog.errors import CH_TRANSIENT_ERRORS
+from posthog.errors import CH_TRANSIENT_ERRORS, CHQueryErrorUnknownTable
from posthog.exceptions import ClickHouseAtCapacity
from posthog.exceptions_capture import capture_exception
from posthog.metrics import pushed_metrics_registry
@@ -982,12 +982,15 @@ def find_flags_with_enriched_analytics() -> None:
try:
find_flags_with_enriched_analytics(begin, end)
+ except CHQueryErrorUnknownTable as e:
+ # Expected on self-hosted instances with an incomplete ClickHouse schema (e.g. missing
+ # migrations) - not worth capturing as an exception, just skip this run.
+ logger.warning("Find flags with enriched analytics skipped, table missing", error=e)
except Exception as e:
logger.exception("Find flags with enriched analytics failed", error=e)
capture_exception(
e, additional_properties={"feature": "feature_flags", "task": "find_flags_with_enriched_analytics"}
)
- raise
@shared_task(ignore_result=True)
diff --git a/posthog/test/test_feature_flag_analytics.py b/posthog/test/test_feature_flag_analytics.py
index 2eabe3b326e1..a41949749a28 100644
--- a/posthog/test/test_feature_flag_analytics.py
+++ b/posthog/test/test_feature_flag_analytics.py
@@ -19,6 +19,7 @@ from django.core.cache import cache
from posthog import redis
from posthog.constants import FlagRequestType
+from posthog.errors import CHQueryErrorUnknownTable
from posthog.models.team.team import Team
from posthog.tasks.tasks import find_flags_with_enriched_analytics as find_flags_with_enriched_analytics_task
@@ -1038,14 +1039,23 @@ class TestEnrichedAnalytics(BaseTest):
class TestFindFlagsWithEnrichedAnalyticsTask(BaseTest):
@patch("products.feature_flags.backend.flag_analytics.find_flags_with_enriched_analytics")
- def test_logs_and_reraises_on_failure(self, mock_find_flags: MagicMock) -> None:
+ def test_logs_and_captures_on_failure_without_reraising(self, mock_find_flags: MagicMock) -> None:
mock_find_flags.side_effect = Exception("boom")
- with patch("posthog.tasks.tasks.capture_exception") as mock_capture, self.assertRaises(Exception):
+ with patch("posthog.tasks.tasks.capture_exception") as mock_capture:
find_flags_with_enriched_analytics_task()
mock_capture.assert_called_once()
+ @patch("products.feature_flags.backend.flag_analytics.find_flags_with_enriched_analytics")
+ def test_unknown_table_error_is_not_captured(self, mock_find_flags: MagicMock) -> None:
+ mock_find_flags.side_effect = CHQueryErrorUnknownTable("Table default.events doesn't exist", code=60)
+
+ with patch("posthog.tasks.tasks.capture_exception") as mock_capture:
+ find_flags_with_enriched_analytics_task()
+
+ mock_capture.assert_not_called()
+
class TestCrossProjectEvaluations(ClickhouseTestMixin, APIBaseTest):
def test_returns_zero_when_no_events(self):