Skip to content

Commit bc8ceb2

Browse files
patch different form method
1 parent 064ed6a commit bc8ceb2

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

sentry_sdk/integrations/starlette.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,32 +503,37 @@ def _patch_json_request_body_accessor() -> None:
503503
_original_json = Request.json
504504

505505
@functools.wraps(_original_json)
506-
async def sentry_json(self: "Request", *args: "Any", **kwargs: "Any") -> "Any":
506+
async def wrapped_json(self: "Request", *args: "Any", **kwargs: "Any") -> "Any":
507507
request_json = await _original_json(self, *args, **kwargs)
508508
self.scope.setdefault("state", {})[_SCOPE_STATE_JSON_REQUEST_BODY_KEY] = (
509509
request_json
510510
)
511511
return request_json
512512

513-
Request.json = sentry_json
513+
Request.json = wrapped_json
514514

515515

516516
def _patch_formdata_request_body_accessor() -> None:
517517
"""
518518
Caches request body data on the ASGI scope, so that the body can be attached to telemetry after the request handler runs.
519519
Without the cache, consuming the stream can cause the application to hang.
520520
"""
521-
_original_form = Request.form
521+
if not hasattr(Request, "_get_form"):
522+
return
523+
524+
_original_form = Request._get_form
522525

523526
@functools.wraps(_original_form)
524-
async def sentry_form(self: "Request", *args: "Any", **kwargs: "Any") -> "FormData":
527+
async def wrapped_form(
528+
self: "Request", *args: "Any", **kwargs: "Any"
529+
) -> "FormData":
525530
request_formdata = await _original_form(self, *args, **kwargs)
526531
self.scope.setdefault("state", {})[_SCOPE_STATE_FORMDATA_REQUEST_BODY_KEY] = (
527532
request_formdata
528533
)
529534
return request_formdata
530535

531-
Request.form = sentry_form
536+
Request._get_form = wrapped_form
532537

533538

534539
def _serialize_cached_request_body_attribute(

0 commit comments

Comments
 (0)