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): inject source-product context on report detail views (#62811)

posthog[bot]e290472a0044
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 1e3c8efbb8b9..566c047df91b 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -3,6 +3,7 @@ from datetime import timedelta
from urllib.parse import urlencode
from posthog.test.base import APIBaseTest
+from unittest.mock import patch
from django.utils import timezone
@@ -611,13 +612,40 @@ class TestSignalReportListAPI(APIBaseTest):
row = next(r for r in response.json()["results"] if r["id"] == str(report.id))
assert row["source_products"] == []
- def test_source_products_empty_on_retrieve(self):
+ def test_source_products_empty_on_retrieve_without_signals(self):
report = self._create_report()
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"] == []
+ def test_source_products_present_on_retrieve(self):
+ report = self._create_report()
+
+ with patch(
+ "products.signals.backend.views.fetch_source_products_for_reports",
+ return_value={str(report.id): ["zendesk", "github"]},
+ ):
+ 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"] == ["zendesk", "github"]
+
+ def test_source_products_present_on_signals_action(self):
+ report = self._create_report()
+
+ with (
+ patch(
+ "products.signals.backend.views.fetch_source_products_for_reports",
+ return_value={str(report.id): ["zendesk"]},
+ ),
+ patch("products.signals.backend.views.fetch_signals_for_report_sync", return_value=[]),
+ ):
+ response = self.client.get(f"/api/projects/{self.team.id}/signals/reports/{report.id}/signals/")
+
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()["report"]["source_products"] == ["zendesk"]
+
# --- legacy choice removal ---
def test_actionability_null_for_legacy_choice_artefact(self):
@@ -719,6 +747,22 @@ class TestSignalReportSuppressionAPI(APIBaseTest):
assert content["user_id"] == self.user.id
assert content["user_uuid"] == str(self.user.uuid)
+ def test_state_transition_response_includes_source_products(self):
+ report = self._create_report()
+
+ with patch(
+ "products.signals.backend.views.fetch_source_products_for_reports",
+ return_value={str(report.id): ["zendesk"]},
+ ):
+ 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"] == ["zendesk"]
+
@parameterized.expand(
[
(
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index 41b63ece6261..2d1fe1c3e533 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -699,6 +699,21 @@ class SignalReportViewSet(
def get_serializer_context(self):
return {**super().get_serializer_context(), "team": self.team}
+ 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.
+ report_ids = [str(report.id)]
+ 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),
+ }
+
+ def retrieve(self, request, *args, **kwargs):
+ report = self.get_object()
+ serializer = self.get_serializer(report, context=self._enriched_report_context(report))
+ return Response(serializer.data)
+
@extend_schema(
parameters=[
OpenApiParameter(
@@ -852,7 +867,7 @@ class SignalReportViewSet(
def signals(self, request, pk=None, **kwargs):
"""Fetch all signals for a report from ClickHouse, including full metadata."""
report = self.get_object()
- report_data = SignalReportSerializer(report).data
+ report_data = SignalReportSerializer(report, context=self._enriched_report_context(report)).data
signals_list = fetch_signals_for_report_sync(self.team, str(report.id))
return Response({"report": report_data, "signals": signals_list})
@@ -933,7 +948,7 @@ class SignalReportViewSet(
content=json.dumps(artefact_content),
)
- return Response(SignalReportSerializer(report, context=self.get_serializer_context()).data)
+ return Response(SignalReportSerializer(report, context=self._enriched_report_context(report)).data)
@extend_schema(exclude=True)
@action(detail=True, methods=["post"], url_path="reingest", required_scopes=["task:write"])