When minidumps feature is turned off, don't 500 when sent

Fix #293
This commit is contained in:
Klaas van Schelven
2026-01-06 19:33:07 +01:00
parent 5cf185388e
commit e6c163c674
2 changed files with 39 additions and 4 deletions

View File

@@ -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")

View File

@@ -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.")