Skip to content

Commit 03b7c12

Browse files
authored
Handle MultiPartParserError to avoid internal sentry crash
Handles an internal error in sentry_sdk if there is an issue with parsing request.POST. See attached stack trace of this internal error that we experienced in production. It would be better to handle this exception without request data instead of crashing and not reporting anything. ``` [sentry] ERROR: Internal error in sentry_sdk Traceback (most recent call last): File "/usr/src/app/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/django/__init__.py", line 588, in parsed_body return self.request.data ^^^^^^^^^^^^^^^^^ AttributeError: 'WSGIRequest' object has no attribute 'data' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/app/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/django/__init__.py", line 508, in wsgi_request_event_processor DjangoRequestExtractor(request).extract_into_event(event) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "/usr/src/app/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/_wsgi_common.py", line 118, in extract_into_event parsed_body = self.parsed_body() File "/usr/src/app/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/django/__init__.py", line 590, in parsed_body return RequestExtractor.parsed_body(self) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/usr/src/app/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/_wsgi_common.py", line 152, in parsed_body form = self.form() File "/usr/src/app/.venv/lib/python3.13/site-packages/sentry_sdk/integrations/django/__init__.py", line 575, in form return self.request.POST ^^^^^^^^^^^^^^^^^ File "/usr/src/app/.venv/lib/python3.13/site-packages/django/core/handlers/wsgi.py", line 93, in _get_post self._load_post_and_files() ~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/usr/src/app/.venv/lib/python3.13/site-packages/django/http/request.py", line 374, in _load_post_and_files self._post, self._files = self.parse_file_upload(self.META, data) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/usr/src/app/.venv/lib/python3.13/site-packages/django/http/request.py", line 321, in parse_file_upload parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding) File "/usr/src/app/.venv/lib/python3.13/site-packages/django/http/multipartparser.py", line 89, in __init__ raise MultiPartParserError( "Invalid boundary in multipart: %s" % force_str(boundary) ) django.http.multipartparser.MultiPartParserError: Invalid boundary in multipart: None ```
1 parent 5a27502 commit 03b7c12

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

sentry_sdk/integrations/django/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from django.conf import settings as django_settings
3636
from django.core import signals
3737
from django.conf import settings
38+
from django.http.multipartparser import MultiPartParserError
3839

3940
try:
4041
from django.urls import resolve
@@ -586,6 +587,8 @@ def parsed_body(self):
586587
return self.request.data
587588
except AttributeError:
588589
return RequestExtractor.parsed_body(self)
590+
except MultiPartParserError:
591+
return None
589592

590593

591594
def _set_user_info(request, event):

0 commit comments

Comments
 (0)