From 5cf185388ea727081e5d8bd8a63c12a718bab406 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Tue, 6 Jan 2026 16:23:45 +0100 Subject: [PATCH] Fix exception for unsupported envelope items See #293 --- ingest/tests.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ ingest/views.py | 4 ++++ 2 files changed, 57 insertions(+) diff --git a/ingest/tests.py b/ingest/tests.py index 116bfd5..513dfa3 100644 --- a/ingest/tests.py +++ b/ingest/tests.py @@ -418,6 +418,59 @@ class IngestViewTestCase(TransactionTestCase): self.assertEqual('SIGABRT: Fatal Error: SIGABRT', Event.objects.get().title()) + def test_envelope_endpoint_unsupported_type(self): + # dirty copy/paste from the integration test, let's start with "something", we can always clean it later. + project = Project.objects.create(name="test") + + sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }") + + for i, include_event_id in enumerate([True, False]): + data = {} + event_id = uuid.uuid4().hex + + data_bytes = json.dumps(data).encode("utf-8") + data_bytes = ( + b'{"event_id": "%s"}\n{"type": "unsupported_type"}\n' % event_id.encode("utf-8") + data_bytes) + + response = self.client.post( + f"/api/{ project.id }/envelope/", + content_type="application/json", + headers={ + "X-Sentry-Auth": sentry_auth_header, + }, + data=data_bytes, + ) + self.assertEqual( + 200, response.status_code, response.content if response.status_code != 302 else response.url) + + self.assertEqual(0, Event.objects.count()) + + def test_envelope_endpoint_unsupported_type_without_event_id(self): + # dirty copy/paste from the integration test, let's start with "something", we can always clean it later. + project = Project.objects.create(name="test") + + sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }") + + for i, include_event_id in enumerate([True, False]): + data = {} + + data_bytes = json.dumps(data).encode("utf-8") + data_bytes = ( + b'{}\n{"type": "unsupported_type"}\n' + data_bytes) + + response = self.client.post( + f"/api/{ project.id }/envelope/", + content_type="application/json", + headers={ + "X-Sentry-Auth": sentry_auth_header, + }, + data=data_bytes, + ) + self.assertEqual( + 200, response.status_code, response.content if response.status_code != 302 else response.url) + + self.assertEqual(0, Event.objects.count()) + @tag("samples") def test_envelope_endpoint_reused_ids_different_exceptions(self): # dirty copy/paste from test_envelope_endpoint, diff --git a/ingest/views.py b/ingest/views.py index e5ff1bc..8defdad 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -716,6 +716,10 @@ class IngestEnvelopeAPIView(BaseIngestAPIView): event_count = len(items_by_type.get("event", [])) minidump_count = len(items_by_type.get("attachment", [])) + if event_count + minidump_count == 0: + logger.info("no event or minidump found in envelope, ignoring this envelope.") + return HttpResponse() + if event_count > 1 or minidump_count > 1: # TODO: we do 2 passes (one for storing, one for calling the right task), and we check certain conditions # only on the second pass; this means that we may not clean up after ourselves yet.