Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry's http putrequest override breaks if url is None, while native http does not #1678

Closed
cpak opened this issue Oct 13, 2022 · 0 comments · Fixed by #1693
Closed

Sentry's http putrequest override breaks if url is None, while native http does not #1678

cpak opened this issue Oct 13, 2022 · 0 comments · Fixed by #1693
Labels
Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest!

Comments

@cpak
Copy link

cpak commented Oct 13, 2022

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.9.10

Steps to Reproduce

Example code

import sentry_sdk
from http.client import HTTPConnection

print("sending reqeust with None url before sentry_sdk.init")
HTTPConnection("httpbin.org", port=443).putrequest("POST", None)
print("OK")

sentry_sdk.init(dsn="")
print("sending reqeust with None url after sentry_sdk.init")
HTTPConnection("httpbin.org", port=443).putrequest("POST", None)
print("OK")

Output:

sending reqeust with None url before sentry_sdk.init
OK
sending reqeust with None url after sentry_sdk.init
Traceback (most recent call last):
  File "/Users/cpak/projects/sentry-httplib-bug/main.py", line 10, in <module>
    HTTPConnection("httpbin.org", port=443).putrequest("POST", None)
  File "/Users/cpak/projects/sentry-httplib-bug/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/stdlib.py", line 73, in putrequest
    if not real_url.startswith(("http://", "https://")):
AttributeError: 'NoneType' object has no attribute 'startswith'

Expected Result

I expect Sentry's http instrumentation to not alter the behavior of the underlying code.

I ran into this issue because a package I'm using (azure-data-tables) apparently tries to send requests with a None url, i.e. I don't really have any control over this. It worked locally but not on our remote servers, which turned out to be because we have Sentry running on those servers 😅

Actual Result

An AttributeError: 'NoneType' object has no attribute 'startswith' is raised.

FWIW the native implementation has this line

url = url or '/'
@cpak cpak changed the title Sentry's http putrequest override breaks if url is None, while native httplib does not Sentry's http putrequest override breaks if url is None, while native http does not Oct 13, 2022
@sl0thentr0py sl0thentr0py added Status: Untriaged Hacktoberfest 🎃 Issues eligible for Hacktoberfest! labels Oct 13, 2022
@sl0thentr0py sl0thentr0py added the Good first issue Good for newcomers label Oct 13, 2022
MattFlower pushed a commit to MattFlower/sentry-python that referenced this issue Oct 19, 2022
Modifies behavior of putrequest to check for None on real_url prior to using it.

Fixes getsentryGH-1678.
MattFlower pushed a commit to MattFlower/sentry-python that referenced this issue Oct 19, 2022
Modifies behavior of putrequest to check for None on real_url prior to using it.

Fixes getsentryGH-1678
antonpirker pushed a commit that referenced this issue Oct 20, 2022
Modifies behavior of putrequest to check for None on real_url prior to using it.

Fixes GH-1678

Co-authored-by: Matthew Flower <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants