: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(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.pyindex 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 AsyncGeneratorfrom datetime import datetimefrom typing import Anyfrom urllib.parse import parse_qs, urlparse+from uuid import UUIDfrom django.conf import settingsfrom 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_iddef _user_id(self) -> int | None:diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex 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):