Skip to content

Commit d07b09d

Browse files
committed
Merge branch 'master' into major/3.0
2 parents cf69604 + ec53096 commit d07b09d

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎sentry_sdk/consts.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ def __init__(
12821282
profile_lifecycle: 'Literal["manual", "trace"]' = "manual",
12831283
profile_session_sample_rate: "Optional[float]" = None,
12841284
auto_enabling_integrations: bool = True,
1285-
disabled_integrations: "Optional[Sequence[sentry_sdk.integrations.Integration]]" = None,
1285+
disabled_integrations: "Optional[Sequence[Union[sentry_sdk.integrations.Integration, type[sentry_sdk.integrations.Integration]]]]" = None,
12861286
auto_session_tracking: bool = True,
12871287
send_client_reports: bool = True,
12881288
_experiments: "Experiments" = {}, # noqa: B006

‎sentry_sdk/integrations/bottle.py‎

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

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

7891
@ensure_integration_enabled(BottleIntegration, old_app)

‎sentry_sdk/serializer.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343

4444
# Maximum depth and breadth of databags. Excess data will be trimmed. If
4545
# max_request_body_size is "always", request bodies won't be trimmed.
46-
MAX_DATABAG_DEPTH = 5
47-
MAX_DATABAG_BREADTH = 10
46+
MAX_DATABAG_DEPTH: int = 5
47+
MAX_DATABAG_BREADTH: int = 10
4848
CYCLE_MARKER = "<cyclic>"
4949

5050

‎tests/integrations/bottle/test_bottle.py‎

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

105105

106+
def test_attach_stacktrace_doesnt_hang(sentry_init, capture_events, app, get_client):
107+
sentry_init(
108+
integrations=[BottleIntegration()],
109+
max_request_body_size="always",
110+
attach_stacktrace=True,
111+
)
112+
113+
data = {"foo": {"bar": "a" * (1024)}}
114+
115+
@app.route("/", method="POST")
116+
def index():
117+
import bottle
118+
119+
assert bottle.request.json == data
120+
assert bottle.request.body.read() == json.dumps(data).encode("ascii")
121+
capture_message("hi")
122+
return "ok"
123+
124+
events = capture_events()
125+
126+
client = get_client()
127+
response = client.get("/")
128+
129+
response = client.post("/", content_type="application/json", data=json.dumps(data))
130+
assert response[1] == "200 OK"
131+
132+
(event,) = events
133+
134+
# As long as this test finishes, we're good. It's just making sure we don't
135+
# hang.
136+
assert event["request"]["data"]
137+
138+
106139
@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
107140
def test_empty_json_request(sentry_init, capture_events, app, data, get_client):
108141
sentry_init(integrations=[BottleIntegration()])

0 commit comments

Comments
 (0)