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(signals): make report enrichment best-effort on detail views (#63617)

Andrew Maguiref96929d96002
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 566c047df91b..acd329f6713e 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -646,6 +646,18 @@ class TestSignalReportListAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK
assert response.json()["report"]["source_products"] == ["zendesk"]
+ def test_source_products_resilient_to_clickhouse_failure_on_retrieve(self):
+ report = self._create_report()
+
+ with patch(
+ "products.signals.backend.views.fetch_source_products_for_reports",
+ side_effect=Exception("clickhouse timeout"),
+ ):
+ response = self.client.get(f"/api/projects/{self.team.id}/signals/reports/{report.id}/")
+
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()["source_products"] == []
+
# --- legacy choice removal ---
def test_actionability_null_for_legacy_choice_artefact(self):
@@ -763,6 +775,26 @@ class TestSignalReportSuppressionAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK, response.json()
assert response.json()["source_products"] == ["zendesk"]
+ def test_state_transition_resilient_to_clickhouse_failure(self):
+ # A ClickHouse hiccup during best-effort enrichment must not 500 an already-committed
+ # state change — the transition is persisted and the response degrades to empty.
+ report = self._create_report()
+
+ with patch(
+ "products.signals.backend.views.fetch_source_products_for_reports",
+ side_effect=Exception("clickhouse timeout"),
+ ):
+ response = self.client.post(
+ self._state_url(str(report.id)),
+ data=json.dumps({"state": "suppressed"}),
+ content_type="application/json",
+ )
+
+ assert response.status_code == status.HTTP_200_OK, response.json()
+ assert response.json()["source_products"] == []
+ report.refresh_from_db()
+ assert report.status == SignalReport.Status.SUPPRESSED
+
@parameterized.expand(
[
(
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 2d1fe1c3e533..adcfdea4ce44 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -702,11 +702,24 @@ class SignalReportViewSet(
def _enriched_report_context(self, report: SignalReport) -> dict:
# Detail-view parity with list(): inject the source-product and PR-url maps the
# SignalReportSerializer reads, so single-report responses aren't silently degraded.
+ # Both lookups are best-effort: the serializer degrades to empty values when a map
+ # is missing, so a ClickHouse/Postgres hiccup must not turn an otherwise-available
+ # report (or an already-committed state change) into a 500.
report_ids = [str(report.id)]
+ try:
+ source_products_map = fetch_source_products_for_reports(self.team, report_ids)
+ except Exception:
+ logger.exception("signals.enriched_context.source_products_failed", report_id=str(report.id))
+ source_products_map = {}
+ try:
+ implementation_pr_url_map = fetch_implementation_pr_urls_for_reports(report_ids)
+ except Exception:
+ logger.exception("signals.enriched_context.implementation_pr_url_failed", report_id=str(report.id))
+ implementation_pr_url_map = {}
return {
**self.get_serializer_context(),
- "source_products_map": fetch_source_products_for_reports(self.team, report_ids),
- "implementation_pr_url_map": fetch_implementation_pr_urls_for_reports(report_ids),
+ "source_products_map": source_products_map,
+ "implementation_pr_url_map": implementation_pr_url_map,
}
def retrieve(self, request, *args, **kwargs):