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
Webargs 6.0.0 has broken Flaskparser @use_kwargs: Never parses query string or formdata #483
Comments
See the CHANGELOG https://webargs.readthedocs.io/en/latest/changelog.html#b1-2020-01-06 : use_args doesn't check multiple locations by default, and the default location is the JSON payload. To parse from the query params, you should pass |
Is there a way to restore the behavior of parsing query, form-data AND JSON together? This is an important feature for us: we use Swagger UI via flasgger, and document our APIs using form-data because Swagger provides useful text boxes and form controls, but apps talking to our API use exclusively JSON and query parameters. |
You can use multiple calls to |
For complex API endpoints used by developers, mobile apps, Unity games, and websites, this is going to require a lot of code changes and redundant, repeated usages of multiple This 6.0.0 change even broke your own README example on:
|
You can do @use_args(..., location="query"')
@use_args(..., location="json_or_form")
def view_func(...): @captainkw, good catch. We'll fix the README example. Indeed this change impacts code relying on a single call to Meanwhile, the app can still use webargs 5. This changes makes webargs code clearer and more maintainable, and most importantly, it allows the Schema features (pre/post load decorators, unknown fields management) to be used, which was an issue and a source of questions for a lot of users. |
Fixed in |
This bit us today :( ty for updating docs! |
Same @killswitch-GUI ! I spent way too much time looking/tweaking the nginx configuration before looking at the package version. Should've done that earlier. For what its worth: I was using the |
I guess that's what major versions are for. Closing this. Please comment if there are still issues with this change. |
About allowing a parameter to be present in either the query string or the form data:
Unfortunately, this does not work when one of the parameters is required. No matter where the parameter is present, the other call to If I am not mistaken, there is no direct way to search for required parameters in multiple locations at all, something that was totally easy and straightforward in webargs 5.x |
This is an "advanced usage": https://webargs.readthedocs.io/en/latest/advanced.html#meta-locations. |
Thank you for the pointer! I still find it odd that now "advanced usage" is necessary to achieve something which was a (fairly reasonable, IMHO) default behavior before. It would already be very helpful if there was a predefined "location" for the common use-case of query+form+json, but even better would be to allow for |
I would vote to make "form_or_json" be a default location for POST requests. I do agree that mixing query params AND form params in the same request is strange and doesn't need to be supported. But if it's a POST request, it should be able to parse form-data or JSON depending on the Content-Type of the request coming in. i.e. when the client request says "Content-Type: application/x-www-form-urlencoded" webargs would parse as form-data; when it's "application/json", parse it as JSON data. The 5.x.x versions of webargs supported parsing data from either type of POST request and it's a bit tedious now to have to copy-paste a As the state of webargs 6 currently stands, at work we're pinned on 5.5.2 and are considering either forking webargs internally or otherwise write our own drop-in replacement; or for future new APIs we write, to pick a different library to use altogether. |
Can't you just override |
The reason why I would like to support both query params and form params is that I have views which support being called with GET (using query params) or POST (using form params). BTW @kirsle you could also set |
Yes, forget my message above. This is already configurable in
|
Hello,
Your recent release of 6.0.0 of webargs has unexpectedly broken our Flask apps. It seems now the @use_kwargs decorator from the
webargs.flaskparser
completely fails to parse GET query string parameters or POST form-data parameters. Only JSON request bodies ever get parsed anymore.Here is an example Flask app that shows the problem:
The endpoint "/test1" has three optional parameters each with default values when missing. If I make a GET request (with query parameters) or a POST request with application/x-www-form-urlencoded format, webargs completely fails to pick up my parameters and only sees the defaults.
In the endpoint "/test2" I have a required parameter, which again fails to parse on GET or form-data post but works on JSON post only. Here are some curl examples:
The text was updated successfully, but these errors were encountered: