From e6c163c6747dbba5235a183bdd4bca2f98f9c6a5 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Tue, 6 Jan 2026 19:33:07 +0100 Subject: [PATCH] When minidumps feature is turned off, don't 500 when sent Fix #293 --- ingest/tests.py | 35 +++++++++++++++++++++++++++++++++++ ingest/views.py | 8 ++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ingest/tests.py b/ingest/tests.py index 513dfa3..e943a47 100644 --- a/ingest/tests.py +++ b/ingest/tests.py @@ -418,6 +418,41 @@ class IngestViewTestCase(TransactionTestCase): self.assertEqual('SIGABRT: Fatal Error: SIGABRT', Event.objects.get().title()) + @tag("samples") + @override_settings(FEATURE_MINIDUMPS=False) + def test_envelope_endpoint_minidump_only_when_feature_off(self): + # dirty copy/paste from the "feature on" case, with different expectations. + project = Project.objects.create(name="test") + + sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }") + + SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples") + + filename = glob(SAMPLES_DIR + "/minidumps/linux_overflow.dmp")[0] # pick a fixed one for reproducibility + with open(filename, 'rb') as f: + minidump_bytes = f.read() + + event_id = uuid.uuid4().hex # required at the envelope level so we provide it. + + data_bytes = ( + b'{"event_id": "%s"}\n' % event_id.encode("utf-8") + + b'{"type": "attachment", "attachment_type": "event.minidump", "length": %d}\n' % len(minidump_bytes) + + minidump_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(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") diff --git a/ingest/views.py b/ingest/views.py index 8defdad..b87acb9 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -676,9 +676,9 @@ class IngestEnvelopeAPIView(BaseIngestAPIView): item_headers.get("attachment_type") == "event.minidump" and not get_settings().FEATURE_MINIDUMPS)): - # non-event/minidumps can be discarded; (we don't check for individual size limits, because these differ - # per item type, we have the envelope limit to protect us, and we incur almost no cost (NullWriter)) - return NullWriter() + # non-event/minidumps can be discarded; (the somewhat arbitrary size limit is no problem because we have + # the envelope limit to protect us, and we incur almost no cost (NullWriter)) + return MaxDataWriter("MAX_ATTACHMENT_SIZE", NullWriter()) # envelope_headers["event_id"] is required when type in ["event", "attachment"] per the spec (and takes # precedence over the payload's event_id), so we can rely on it having been set. @@ -714,7 +714,7 @@ class IngestEnvelopeAPIView(BaseIngestAPIView): items_by_type[type_].append(output_stream) event_count = len(items_by_type.get("event", [])) - minidump_count = len(items_by_type.get("attachment", [])) + minidump_count = len(items_by_type.get("attachment", [])) if get_settings().FEATURE_MINIDUMPS else 0 if event_count + minidump_count == 0: logger.info("no event or minidump found in envelope, ignoring this envelope.")