Просмотр исходного кода

Fixing update bug not forwarding error to user (#26109)

Chris Fuller 3 лет назад
Родитель
Сommit
987dea01eb

+ 3 - 2
src/sentry/api/endpoints/group_details.py

@@ -269,9 +269,10 @@ class GroupDetailsEndpoint(GroupEndpoint, EnvironmentMixin):
             response = update_groups(
                 request, [group.id], [project], project.organization_id, search_fn, has_inbox
             )
-
             # if action was discard, there isn't a group to serialize anymore
-            if discard:
+            # if response isn't 200, return the response update_groups gave us (i.e. helpful error)
+            # instead of serializing the updated group
+            if discard or response.status_code != 200:
                 return response
 
             # we need to fetch the object against as the bulk mutation endpoint

+ 23 - 0
tests/snuba/api/endpoints/test_group_details.py

@@ -1,3 +1,5 @@
+from rest_framework.exceptions import ErrorDetail
+
 from sentry.models import Environment, GroupInboxReason, Release
 from sentry.models.groupinbox import add_group_to_inbox, remove_group_from_inbox
 from sentry.testutils import APITestCase, SnubaTestCase
@@ -150,3 +152,24 @@ class GroupDetailsTest(APITestCase, SnubaTestCase):
             response = self.client.get(url, format="json")
             assert response.status_code == 200, response.content
             assert response.data["inbox"] is None
+
+    def test_assigned_to_unknown(self):
+        with self.feature("organizations:inbox"):
+            self.login_as(user=self.user)
+            event = self.store_event(
+                data={"timestamp": iso_format(before_now(minutes=3))},
+                project_id=self.project.id,
+            )
+            group = event.group
+            url = f"/api/0/issues/{group.id}/"
+            response = self.client.put(
+                url, {"assignedTo": "admin@localhost", "status": "unresolved"}, format="json"
+            )
+            assert response.status_code == 200
+            response = self.client.put(
+                url, {"assignedTo": "user@doesntexist.com", "status": "unresolved"}, format="json"
+            )
+            assert response.status_code == 400
+            assert response.data == {
+                "assignedTo": [ErrorDetail(string="Unknown actor input", code="invalid")]
+            }