From 91bf3222740cfdf0d035fefc4c7073fb87e29937 Mon Sep 17 00:00:00 2001 From: Orhan Hirsch Date: Fri, 31 Jan 2025 13:48:59 +0100 Subject: [PATCH] Handle MultiPartParserError to avoid internal sentry crash (#4001) Handles an internal error in sentry_sdk if there is an issue with parsing request.POST. It would be better to handle this exception without request data instead of crashing and not reporting anything. --- Co-authored-by: Ivana Kellyer --- sentry_sdk/integrations/_wsgi_common.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/_wsgi_common.py b/sentry_sdk/integrations/_wsgi_common.py index 7266a91f56..48bc432887 100644 --- a/sentry_sdk/integrations/_wsgi_common.py +++ b/sentry_sdk/integrations/_wsgi_common.py @@ -149,8 +149,15 @@ def form(self): def parsed_body(self): # type: () -> Optional[Dict[str, Any]] - form = self.form() - files = self.files() + try: + form = self.form() + except Exception: + form = None + try: + files = self.files() + except Exception: + files = None + if form or files: data = {} if form: