Browse Source

fix(crons): Make mutable copy of request.data for PUT (#49163)

Creates mutable copy of `request.data`
Richard Ortenberg 1 year ago
parent
commit
400236f803

+ 3 - 2
src/sentry/monitors/endpoints/monitor_ingest_checkin_details.py

@@ -70,10 +70,11 @@ class MonitorIngestCheckInDetailsEndpoint(MonitorIngestEndpoint):
             return self.respond(status=400)
 
         # Discard monitor config as it is not used
-        request.data.pop("monitor_config", None)
+        request_data = request.data.copy()
+        request_data.pop("monitor_config", None)
 
         serializer = MonitorCheckInValidator(
-            data=request.data,
+            data=request_data,
             partial=True,
             context={
                 "project": project,

+ 32 - 0
tests/sentry/monitors/endpoints/test_monitor_ingest_checkin_details.py

@@ -82,6 +82,38 @@ class UpdateMonitorIngestCheckinTest(MonitorIngestTestCase):
             assert checkin.date_updated > checkin.date_added
 
     def test_passing(self):
+        monitor = self._create_monitor()
+        monitor_environment = self._create_monitor_environment(monitor, name="dev")
+        for path_func in self._get_path_functions():
+            checkin = MonitorCheckIn.objects.create(
+                monitor=monitor,
+                monitor_environment=monitor_environment,
+                project_id=self.project.id,
+                date_added=monitor.date_added,
+            )
+
+            path = path_func(monitor.guid, checkin.guid)
+            resp = self.client.put(
+                path,
+                data={
+                    "status": "ok",
+                },
+                **self.token_auth_headers,
+            )
+            assert resp.status_code == 200, resp.content
+
+            checkin = MonitorCheckIn.objects.get(id=checkin.id)
+            assert checkin.status == CheckInStatus.OK
+            assert (
+                checkin.monitor_environment.environment.name == monitor_environment.environment.name
+            )
+
+            monitor_environment = MonitorEnvironment.objects.get(id=monitor_environment.id)
+            assert monitor_environment.next_checkin > checkin.date_added
+            assert monitor_environment.status == MonitorStatus.OK
+            assert monitor_environment.last_checkin > checkin.date_added
+
+    def test_passing_with_config(self):
         monitor = self._create_monitor()
         monitor_environment = self._create_monitor_environment(monitor, name="dev")
         for path_func in self._get_path_functions():