Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reqparse raises on any non-JSON request with Werkzeug 2.1.0 #936

Open
emosenkis opened this issue Mar 29, 2022 · 8 comments
Open

reqparse raises on any non-JSON request with Werkzeug 2.1.0 #936

emosenkis opened this issue Mar 29, 2022 · 8 comments

Comments

@emosenkis
Copy link

Werkzeug 2.1.0 makes Request.get_json() raise if request is not JSON, which causes reqparse to raise when it attempts to access Request.json, which it does by default for all arguments without a specified location.

@gumptionthomas
Copy link

Confirmed. Additionally, setting location='args' did not prevent the exception from being raised.

@emosenkis
Copy link
Author

Setting location='args' worked for me (I subclassed RequestParser to make the constructor use a custom Argument, which passes location='args' to super().__init__() when request.is_json is false).

@gumptionthomas
Copy link

@emosenkis That's a clever way to do that! However, after spending some hours investigating this I'm still unable to get the location='args' trick to work. And I'm just parsing a single string query arg (overkill to use the deprecated reqparse for this, I know).

As an aside, props to Github tox workflows that caught this for me (although I spent an hour assuming that I had broken something when I checked in some project documentation changes) ;-)

@hyper750
Copy link

As workaround downgrading to Werkzeug 2.0.3 does the trick.

@gumptionthomas
Copy link

I ended up moving to marshmallow for my query param parsing. It was very straight-forward. I'm still using Flask-RESTful for its Resource functionality.

jwoytek pushed a commit to jwoytek/flask-restful that referenced this issue Mar 30, 2022
@davidism
Copy link

davidism commented Mar 30, 2022

It seems like Flask-Restful isn't actively maintained anymore according to #883, which lists alternatives, including Marshmallow in place of reqparse.

Flask-Restx seems to be based on the similar code, and has this PR open: python-restx/flask-restx#423. The same could be applied here.

Given that this isn't actively maintained, it's likely that other things will continue to diverge in incompatible ways. So if you're still using Flask-Restful, it's a very good idea to pin your dependency tree to avoid updates. Or migrate to the suggested alternatives (and still pin to control updates).

@jwoytek
Copy link

jwoytek commented Mar 30, 2022

I've submitted a potential fix for this issue. FWIW, I also reported the issue at werkzeug (pallets/werkzeug#2339), as there may be other broken things, and it took me a bit to narrow down where the problem was.

[edit: I'm a dork and didn't get the link right for the issue]

bkochendorfer added a commit to mozilla-iam/cis that referenced this issue Jun 16, 2022
There were several issues with these tests preventing them from working.

* The parallelism caused port collision despite using a random port
* The `run_before` section in tox.ini caused several issues in parallel
  as it was killing the testing harness for other tests while running
* There is a bug in flask-restful which prevents it from correctly
  parsing args if you do not specify location and are running inside a
  virtual environment. flask-restful/flask-restful#936
* Moto changed it's testing signature requiring arity of two.
* The psycopg2 manually installed version doesn't seem to work correctly
  in the tests and there are comments saying as much
bkochendorfer added a commit to mozilla-iam/cis that referenced this issue Jun 16, 2022
There were several issues with these tests preventing them from working.

* The parallelism caused port collision despite using a random port
* The `run_before` section in tox.ini caused several issues in parallel
  as it was killing the testing harness for other tests while running
* There is a bug in flask-restful which prevents it from correctly
  parsing args if you do not specify location and are running inside a
  virtual environment. flask-restful/flask-restful#936
* Moto changed it's testing signature requiring arity of two.
* The psycopg2 manually installed version doesn't seem to work correctly
  in the tests and there are comments saying as much
@cainmagi
Copy link

Setting location='args' worked for me (I subclassed RequestParser to make the constructor use a custom Argument, which passes location='args' to super().__init__() when request.is_json is false).

It seems that letting location="values" also works.

bunop added a commit to cnr-ibba/SMARTER-backend that referenced this issue Sep 18, 2023
flask-mongoengine and flask-restful have issues with flask and werkzeug latest release. See flask-restful/flask-restful#936 and MongoEngine/flask-mongoengine#522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants