: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(signals): return 404 for non-UUID report_id on artefact endpoints (#69194)
posthog[bot]5a118d47e274
diff --git a/products/signals/backend/test/test_signal_report_artefact_api.py b/products/signals/backend/test/test_signal_report_artefact_api.pyindex db81a791735a..23f8fad1fead 100644--- a/products/signals/backend/test/test_signal_report_artefact_api.py+++ b/products/signals/backend/test/test_signal_report_artefact_api.py@@ -149,6 +149,13 @@ class TestSignalReportArtefactViewSet(APIBaseTest):assert len(results) == 1assert results[0]["content"][0]["github_login"] == "alice"+ @parameterized.expand([("sig_praise",), ("bulk_download",), ("not-a-uuid",)])+ def test_list_non_uuid_report_id_returns_404_not_500(self, report_id):+ # Agents whose prompt only carries a signal_id pass it as report_id; it can never be a+ # report UUID, so this must 404 rather than 500 from the ORM coercing it to a UUID.+ response = self.client.get(self._list_url(report_id))+ assert response.status_code == status.HTTP_404_NOT_FOUND+# --- GET retrieve ---def test_retrieve_returns_single_enriched_artefact(self):@@ -708,6 +715,15 @@ class TestSignalReportArtefactLogWriteViewSet(APIBaseTest):assert artefact.team_id == self.team.idassert json.loads(artefact.content) == _CODE_REFERENCE_CONTENT+ def test_post_non_uuid_report_id_returns_404_not_500(self):+ # The create guard has its own report lookup, distinct from the read path's queryset.+ response = self.client.post(+ self._list_url("sig_praise"),+ data=json.dumps({"artefact_type": "note", "content": {"note": "x"}}),+ content_type="application/json",+ )+ assert response.status_code == status.HTTP_404_NOT_FOUND+@parameterized.expand([("code_reference", _CODE_REFERENCE_CONTENT),diff --git a/products/signals/backend/views.py b/products/signals/backend/views.pyindex 2df0b06c41a6..e83086bd877a 100644--- a/products/signals/backend/views.py+++ b/products/signals/backend/views.py@@ -1551,6 +1551,20 @@ class SignalReportViewSet(return Response({"status": "reingestion_started", "report_id": report_id}, status=status.HTTP_202_ACCEPTED)+# `report_id` addresses a report's UUID primary key. Agents whose prompt only carries a+# `signal_id` sometimes pass that (e.g. `sig_praise`) here instead, so make the constraint+# explicit in the schema — a non-UUID value can never match a report.+_REPORT_ID_PARAMETER = OpenApiParameter(+ name="report_id",+ type=OpenApiTypes.UUID,+ location=OpenApiParameter.PATH,+ description=(+ "UUID of the report whose artefacts you're addressing. This must be a report id (the "+ "report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404."+ ),+)++@extend_schema_view(list=extend_schema(summary="List a report's artefacts",@@ -1561,12 +1575,14 @@ class SignalReportViewSet("and log entries (code references, commits, task runs, notes). ""`suggested_reviewers` content is enriched with PostHog user info at read time."),+ parameters=[_REPORT_ID_PARAMETER],responses={200: SignalReportArtefactSerializer(many=True)},operation_id="signals_report_artefacts_list",),retrieve=extend_schema(summary="Get a single artefact",description="Get one artefact by id, content parsed (and reviewers enriched) the same way as the list.",+ parameters=[_REPORT_ID_PARAMETER],responses={200: SignalReportArtefactSerializer},operation_id="signals_report_artefacts_retrieve",),@@ -1608,11 +1624,22 @@ class SignalReportArtefactViewSet(queryset = SignalReportArtefact.objects.select_related("created_by").order_by("-created_at")http_method_names = ["get", "post", "put", "patch", "delete", "head", "options"]+ def _validated_report_id(self) -> str:+ # `report_id` addresses a report's UUID primary key. Agents sometimes pass a signal id+ # (e.g. `sig_praise`) instead, which the ORM can't coerce to a UUID — left to reach the+ # query it surfaces as a 500. Reject it up front as a clean 404 the caller can recover from.+ report_id = self.parents_query_dict["report_id"]+ try:+ uuid.UUID(str(report_id))+ except (ValueError, TypeError):+ raise NotFound()+ return report_id+def safely_get_queryset(self, queryset):# Mirror SignalReportViewSet: a deleted parent report is unreachable, so# its artefacts must be too (otherwise a known UUID would bypass deletion).return queryset.filter(- report_id=self.parents_query_dict["report_id"],+ report_id=self._validated_report_id(),team=self.team,).exclude(report__status=SignalReport.Status.DELETED)@@ -1852,6 +1879,7 @@ class SignalReportArtefactViewSet(404: OpenApiResponse(description="Report not found for this project."),},parameters=[+ _REPORT_ID_PARAMETER,OpenApiParameter(name=TASK_ID_HEADER,type=OpenApiTypes.UUID,@@ -1874,7 +1902,7 @@ class SignalReportArtefactViewSet(operation_id="signals_report_artefacts_create",)def create(self, request: ValidatedRequest, *args, **kwargs) -> Response:- report_id = self.parents_query_dict["report_id"]+ report_id = self._validated_report_id()# A deleted / foreign report is unreachable — don't let a known report_id attach# artefacts to it. Mirrors the team-scoped filter in `safely_get_queryset`.report_exists = (@@ -1969,6 +1997,7 @@ class SignalReportArtefactViewSet("changes the report's canonical status (latest-wins); to re-assess while keeping history, ""append a new artefact instead. Attribution is creation-time only — edits don't reassign it."),+ parameters=[_REPORT_ID_PARAMETER],operation_id="signals_report_artefacts_partial_update",)def partial_update(self, request: ValidatedRequest, *args, **kwargs) -> Response:@@ -1999,6 +2028,7 @@ class SignalReportArtefactViewSet("Delete an artefact, addressed by id. Deleting the latest row of a status type reverts ""the report's canonical status to the previous version (latest-wins over what remains)."),+ parameters=[_REPORT_ID_PARAMETER],operation_id="signals_report_artefacts_destroy",)def destroy(self, request, *args, **kwargs) -> Response:@@ -2022,6 +2052,7 @@ class SignalReportArtefactViewSet("branch via the team's GitHub integration — using the branch's current tip so the diff ""reflects the latest state of the work, not just the single recorded commit."),+ parameters=[_REPORT_ID_PARAMETER],operation_id="signals_report_artefacts_diff",)@action(detail=True, methods=["get"], url_path="diff", required_scopes=["task:read"])diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.tsindex 75cd22a49429..4981292338af 100644--- a/services/mcp/src/generated/signals/api.ts+++ b/services/mcp/src/generated/signals/api.ts@@ -187,7 +187,11 @@ export const SignalsReportArtefactsListParams = /* @__PURE__ */ zod.object({.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- report_id: zod.string(),+ report_id: zod+ .string()+ .describe(+ "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404."+ ),})export const SignalsReportArtefactsListQueryParams = /* @__PURE__ */ zod.object({@@ -205,7 +209,11 @@ export const SignalsReportArtefactsCreateParams = /* @__PURE__ */ zod.object({.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- report_id: zod.string(),+ report_id: zod+ .string()+ .describe(+ "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404."+ ),})export const SignalsReportArtefactsCreateHeader = /* @__PURE__ */ zod.object({@@ -245,7 +253,11 @@ export const SignalsReportArtefactsRetrieveParams = /* @__PURE__ */ zod.object({.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- report_id: zod.string(),+ report_id: zod+ .string()+ .describe(+ "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404."+ ),})/**@@ -259,7 +271,11 @@ export const SignalsReportArtefactsPartialUpdateParams = /* @__PURE__ */ zod.obj.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- report_id: zod.string(),+ report_id: zod+ .string()+ .describe(+ "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404."+ ),})export const SignalsReportArtefactsPartialUpdateBody = /* @__PURE__ */ zod@@ -284,7 +300,11 @@ export const SignalsReportArtefactsDestroyParams = /* @__PURE__ */ zod.object({.describe("Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."),- report_id: zod.string(),+ report_id: zod+ .string()+ .describe(+ "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404."+ ),})/**diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.jsonindex 43b77622abd5..6944179ef6d3 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json@@ -9,6 +9,7 @@"description": "The artefact payload as a JSON object or array; shape depends on artefact_type and is validated against its schema."},"report_id": {+ "description": "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-delete.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-delete.jsonindex 976e15c62a4c..c2461ff5f675 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-delete.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-delete.json@@ -6,6 +6,7 @@"type": "string"},"report_id": {+ "description": "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-list.jsonindex a1e43f676b10..ae5140a89dce 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-list.json@@ -10,6 +10,7 @@"type": "number"},"report_id": {+ "description": "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-retrieve.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-retrieve.jsonindex 976e15c62a4c..c2461ff5f675 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-retrieve.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-retrieve.json@@ -6,6 +6,7 @@"type": "string"},"report_id": {+ "description": "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-update.jsonindex fd4447c9ec9a..886a3f6bd4e9 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-update.json@@ -9,6 +9,7 @@"type": "string"},"report_id": {+ "description": "UUID of the report whose artefacts you're addressing. This must be a report id (the report's own UUID), not a signal id such as `sig_praise` — a non-report id returns 404.","type": "string"}},