From 921d208da3bc44c56138c0da0fdc15a362c8ae41 Mon Sep 17 00:00:00 2001 From: Ben White Date: Tue, 19 Mar 2024 16:36:55 +0100 Subject: [PATCH] fix: Return no content on password reset (#21003) --- posthog/api/authentication.py | 4 ++++ posthog/api/test/test_authentication.py | 1 + 2 files changed, 5 insertions(+) diff --git a/posthog/api/authentication.py b/posthog/api/authentication.py index 9b7dc954a97fa..10538c1d77ceb 100644 --- a/posthog/api/authentication.py +++ b/posthog/api/authentication.py @@ -179,6 +179,10 @@ def create(self, request: Request, *args: Any, **kwargs: Any) -> Response: """ response = super().create(request, *args, **kwargs) response.status_code = getattr(self, "SUCCESS_STATUS_CODE", status.HTTP_200_OK) + + if response.status_code == status.HTTP_204_NO_CONTENT: + response.data = None + return response diff --git a/posthog/api/test/test_authentication.py b/posthog/api/test/test_authentication.py index a33a59dd0549b..ef83517c918c7 100644 --- a/posthog/api/test/test_authentication.py +++ b/posthog/api/test/test_authentication.py @@ -317,6 +317,7 @@ def test_anonymous_user_can_request_password_reset(self, mock_capture): response = self.client.post("/api/reset/", {"email": self.CONFIG_EMAIL}) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(response.content.decode(), "") + self.assertEqual(response.headers["Content-Length"], "0") user: User = User.objects.get(email=self.CONFIG_EMAIL) self.assertEqual(