Skip to content

Commit 026f8ce

Browse files
Stacy W. Smithstacywsmith
Stacy W. Smith
authored andcommitted
Handle Werkzeug 2.1.0 change to Request.get_json().
pallets/werkzeug#2339 changed the behavior of `Request.get_json()` and the `Request.json` property to raise a `BadRequest` if `Request.get_json()` is called without `silent=True`, or the `Request.json` property is accessed, and the content type is not `"application/json"`. Argument parsing allows parsing from multiple locations, and defaults to `["json", "values"]`, but if the locations include `"json"` and the content type is not `"application/json"`, a `BadRequest` is now raised with Werkzeug >= 2.1.0. Invoking `Request.get_json()` with the `silent=True` parameter now handles the situation where `"json"` is included in the locations, but the content type is not `"application/json"`.
1 parent 88497ce commit 026f8ce

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

flask_restx/reqparse.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ def source(self, request):
146146
else:
147147
values = MultiDict()
148148
for l in self.location:
149-
value = getattr(request, l, None)
149+
if l in {"json", "get_json"}:
150+
value = request.get_json(silent=True)
151+
else:
152+
value = getattr(request, l, None)
150153
if callable(value):
151154
value = value()
152155
if value is not None:

0 commit comments

Comments
 (0)