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(autoresearch): return 400 not 500 for a non-object pipeline body (#122469)

posthog[bot]13c2b32efebf
diff --git a/products/autoresearch/backend/presentation/views/views.py b/products/autoresearch/backend/presentation/views/views.py
index a04281647dc3..7b6f25f18dc8 100644
--- a/products/autoresearch/backend/presentation/views/views.py
+++ b/products/autoresearch/backend/presentation/views/views.py
@@ -261,7 +261,8 @@ class AutoresearchPipelineViewSet(TeamAndOrgViewSetMixin, _FacadePaginationMixin
# them on or off, or archives or deletes a pipeline that writes them, needs person:write
# like /score does.
if self.action in ("create", "update", "partial_update"):
- writes_persons = "write_person_property" in request.data
+ # A JSON null or list body is not a dict, so let the serializer reject it with a 400.
+ writes_persons = isinstance(request.data, dict) and "write_person_property" in request.data
elif self.action in ("archive", "destroy") and not getattr(self, "swagger_fake_view", False):
# Schema generation has no pipeline to read, so it documents the base scopes.
writes_persons = api.pipeline_writes_person_property(self.team_id, self.kwargs["pk"])
diff --git a/products/autoresearch/backend/tests/test_api.py b/products/autoresearch/backend/tests/test_api.py
index 14f3f91072e9..3703ce71d9a7 100644
--- a/products/autoresearch/backend/tests/test_api.py
+++ b/products/autoresearch/backend/tests/test_api.py
@@ -875,6 +875,13 @@ class TestAutoresearchPipelineAPI(TeamScopedTestMixin, APIBaseTest):
resp = getattr(self.client, method)(url, body, format="json")
assert (resp.status_code == status.HTTP_403_FORBIDDEN) == refused, (scopes, resp.content)
+ @parameterized.expand([("create", "post", False), ("update", "put", True), ("partial_update", "patch", True)])
+ def test_non_object_body_is_a_validation_error(self, _name: str, method: str, existing: bool):
+ url = f"{self.base_url}/{self._make_pipeline().id}/" if existing else f"{self.base_url}/"
+ for body in ("null", "[]"):
+ resp = getattr(self.client, method)(url, body, content_type="application/json")
+ assert resp.status_code == status.HTTP_400_BAD_REQUEST, (body, resp.content)
+
@parameterized.expand(
[
("while_writing", True, {}, status.HTTP_400_BAD_REQUEST),