Skip to content

Commit 80d886c

Browse files
committed
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 80d886c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: sentry_sdk/integrations/_wsgi_common.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,15 @@ def form(self):
149149

150150
def parsed_body(self):
151151
# type: () -> Optional[Dict[str, Any]]
152-
form = self.form()
153-
files = self.files()
152+
try:
153+
form = self.form()
154+
except Exception:
155+
form = None
156+
try:
157+
files = self.files()
158+
except Exception:
159+
files = None
160+
154161
if form or files:
155162
data = {}
156163
if form:

0 commit comments

Comments
 (0)