Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sentry_sdk/integrations/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ def setup_once() -> None:
version = parse_version(BOTTLE_VERSION)
_check_minimum_version(BottleIntegration, version)

# Bottle's Route.__repr__ might lead to a never-terminating while True
# loop when attach_stacktrace=True.
def _sentry_route_repr(self: "Route") -> str:
cb = self.callback
return "<%s %s -> %s:%s>" % (
self.method,
self.rule,
getattr(cb, "__module__", "?"),
getattr(cb, "__name__", "?"),
)

Route.__sentry_repr__ = _sentry_route_repr

old_app = Bottle.__call__

@ensure_integration_enabled(BottleIntegration, old_app)
Expand Down
33 changes: 33 additions & 0 deletions tests/integrations/bottle/test_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,39 @@ def index():
assert len(event["request"]["data"]["foo"]["bar"]) == 1034


def test_attach_stacktrace_doesnt_hang(sentry_init, capture_events, app, get_client):
sentry_init(
integrations=[BottleIntegration()],
max_request_body_size="always",
attach_stacktrace=True,
)

data = {"foo": {"bar": "a" * (1024)}}

@app.route("/", method="POST")
def index():
import bottle

assert bottle.request.json == data
assert bottle.request.body.read() == json.dumps(data).encode("ascii")
capture_message("hi")
return "ok"

events = capture_events()

client = get_client()
response = client.get("/")

response = client.post("/", content_type="application/json", data=json.dumps(data))
assert response[1] == "200 OK"

(event,) = events

# As long as this test finishes, we're good. It's just making sure we don't
# hang.
assert event["request"]["data"]


@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
def test_empty_json_request(sentry_init, capture_events, app, data, get_client):
sentry_init(integrations=[BottleIntegration()])
Expand Down
Loading