fix(wsgi): Do not catch None#6229
Conversation
None
Codecov Results 📊✅ 33 passed | ⏭️ 2 skipped | Total: 35 | Pass Rate: 94.29% | Execution Time: 7.14s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 25.00%. Project has 15650 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 28.59% 28.45% -0.14%
==========================================
Files 190 190 —
Lines 21903 21873 -30
Branches 7364 7368 +4
==========================================
+ Hits 6261 6223 -38
- Misses 15642 15650 +8
- Partials 558 576 +18Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d02b641. Configure here.
NoneNone and handle None uri
|
|
||
| protocol = None | ||
| if hasattr(uri, "scheme") and uri.scheme is not None: | ||
| if uri is not None and hasattr(uri, "scheme"): |
There was a problem hiding this comment.
Idk if scheme can ever be None but this would be equivalent to the previous check:
| if uri is not None and hasattr(uri, "scheme"): | |
| if uri is not None and getattr(uri, "scheme", None): |
| raw_data = None | ||
| try: | ||
| raw_data = self.raw_data() | ||
| except (RawPostDataException, ValueError): | ||
| except _RAW_DATA_EXCEPTIONS: | ||
| # If DjangoRestFramework is used it already read the body for us | ||
| # so reading it here will fail. We can ignore this. | ||
| pass |
There was a problem hiding this comment.
Bug: In non-Django environments, including RawPostDataException (which is None) in an except block will raise a TypeError when a ValueError occurs, preventing proper exception handling.
Severity: MEDIUM
Suggested Fix
Conditionally construct the tuple of exceptions to catch. Create a list containing ValueError, and only append RawPostDataException to it if RawPostDataException is not None. Then, convert the list to a tuple and use it in the except statement. This ensures None is never part of the exception handler.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: sentry_sdk/integrations/_wsgi_common.py#L113-L119
Potential issue: In environments where Django is not installed, `RawPostDataException`
is initialized to `None`. The `try...except` block at
`sentry_sdk/integrations/_wsgi_common.py:113` attempts to catch a tuple of exceptions
`(RawPostDataException, ValueError)`. When `RawPostDataException` is `None`, this
evaluates to `(None, ValueError)`. Python does not allow non-exception types like `None`
in an `except` clause, so if `self.raw_data()` raises a `ValueError` (an expected
scenario), the program will raise a `TypeError` instead of catching the `ValueError`.
This prevents the intended error handling from running and causes an unhandled
`TypeError` to propagate.
Did we get this right? 👍 / 👎 to inform future reviews.
None and handle None uriNone
f79b4d6
into
webb/test-ci-3

Description
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)