Skip to content

Change to Request.get_json() in Werkzeug 2.1.0 breaks Argument.parse() #422

@stacywsmith

Description

@stacywsmith

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, or the Request.json property
is accessed and the content type is not application/json.

Repro Steps (if applicable)

  1. Install Werkzeug >= 2.1.0
  2. Call parse() on an Argument instance that is from a Request that is NOT content type application/json

Expected Behavior

Argument should be parsed from the query string.

Actual Behavior

raises

werkzeug.exceptions.BadRequest: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Error Messages/Stack Trace

  File "./rest/api/v1/endpoints/services.py", line 207, in get
    args = SERVICES_PARSER.parse_args()
  File "./.tox/py38/lib/python3.8/site-packages/flask_restx/reqparse.py", line 386, in parse_args
    value, found = arg.parse(req, self.bundle_errors)
  File "./.tox/py38/lib/python3.8/site-packages/flask_restx/reqparse.py", line 215, in parse
    source = self.source(request)
  File "./.tox/py38/lib/python3.8/site-packages/flask_restx/reqparse.py", line 149, in source
    value = getattr(request, l, None)
  File "./.tox/py38/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 540, in json
    return self.get_json()
  File "./.tox/py38/lib/python3.8/site-packages/werkzeug/wrappers/request.py", line 571, in get_json
    return self.on_json_loading_failed(None)
  File "./.tox/py38/lib/python3.8/site-packages/flask/wrappers.py", line 133, in on_json_loading_failed
    raise BadRequest() from e
werkzeug.exceptions.BadRequest: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Environment

  • Python version: CPython 3.8.12
  • Flask version: 2.1.0
  • Flask-RESTX version: 0.5.1
  • Other installed Flask extensions: N/A
  • Werkzeug: 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions