Skip to content

Commit ec53096

Browse files
authored
1 parent c624151 commit ec53096

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎sentry_sdk/integrations/bottle.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ def setup_once() -> None:
7575
version = parse_version(BOTTLE_VERSION)
7676
_check_minimum_version(BottleIntegration, version)
7777

78+
# Bottle's Route.__repr__ might lead to a never-terminating while True
79+
# loop when attach_stacktrace=True.
80+
def _sentry_route_repr(self: "Route") -> str:
81+
cb = self.callback
82+
return "<%s %s -> %s:%s>" % (
83+
self.method,
84+
self.rule,
85+
getattr(cb, "__module__", "?"),
86+
getattr(cb, "__name__", "?"),
87+
)
88+
89+
Route.__sentry_repr__ = _sentry_route_repr
90+
7891
old_app = Bottle.__call__
7992

8093
@ensure_integration_enabled(BottleIntegration, old_app)

‎tests/integrations/bottle/test_bottle.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,39 @@ def index():
166166
assert len(event["request"]["data"]["foo"]["bar"]) == 1034
167167

168168

169+
def test_attach_stacktrace_doesnt_hang(sentry_init, capture_events, app, get_client):
170+
sentry_init(
171+
integrations=[BottleIntegration()],
172+
max_request_body_size="always",
173+
attach_stacktrace=True,
174+
)
175+
176+
data = {"foo": {"bar": "a" * (1024)}}
177+
178+
@app.route("/", method="POST")
179+
def index():
180+
import bottle
181+
182+
assert bottle.request.json == data
183+
assert bottle.request.body.read() == json.dumps(data).encode("ascii")
184+
capture_message("hi")
185+
return "ok"
186+
187+
events = capture_events()
188+
189+
client = get_client()
190+
response = client.get("/")
191+
192+
response = client.post("/", content_type="application/json", data=json.dumps(data))
193+
assert response[1] == "200 OK"
194+
195+
(event,) = events
196+
197+
# As long as this test finishes, we're good. It's just making sure we don't
198+
# hang.
199+
assert event["request"]["data"]
200+
201+
169202
@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
170203
def test_empty_json_request(sentry_init, capture_events, app, data, get_client):
171204
sentry_init(integrations=[BottleIntegration()])

0 commit comments

Comments
 (0)