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(tasks): return 404 for malformed task UUID in run views (#66716)

Michael Matlokafe51cd36aa33
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.py
index cd944aebbcb4..00210a617712 100644
--- a/products/tasks/backend/presentation/views/api.py
+++ b/products/tasks/backend/presentation/views/api.py
@@ -7,6 +7,7 @@ from collections.abc import AsyncGenerator
from datetime import datetime
from typing import Any
from urllib.parse import parse_qs, urlparse
+from uuid import UUID
from django.conf import settings
from django.http import HttpResponse, JsonResponse
@@ -742,6 +743,10 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
task_id = self.kwargs.get("parent_lookup_task_id")
if not task_id:
raise NotFound("Task ID is required")
+ try:
+ UUID(task_id)
+ except (ValueError, TypeError):
+ raise NotFound("Task not found")
return task_id
def _user_id(self) -> int | None:
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index b74d37a98621..9bc54fc342bc 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -3287,6 +3287,11 @@ class TestTaskAutomationAPI(BaseTaskAPITest):
class TestTaskRunAPI(BaseTaskAPITest):
+ def test_list_runs_with_malformed_task_id_returns_404(self):
+ # A non-UUID task id in the URL must 404, not 500 through the UUIDField filter.
+ response = self.client.get("/api/projects/@current/tasks/not-a-uuid/runs/")
+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+
@patch("products.tasks.backend.models.TaskRun.publish_stream_state_event")
@patch("products.tasks.backend.facade.api.signal_workflow_completion")
def test_update_run_status_publishes_stream_state_event(self, mock_signal, mock_publish_stream_state_event):