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

Add "bundle_errors" options to send multiple errors for one parse #58

Closed
jfpoilpret opened this issue Aug 26, 2015 · 4 comments

Comments

@jfpoilpret
Copy link

commented Aug 26, 2015

Hi, I just started using webargs with the purpose to fully replace reqparse from Flask-RESTful in my application.
So far I am very happy with webargs nested arguments capabilities (which I could not properly work out with reqparse).

However, with reqparse you have a bundle_errors option, which when set to true, tries to validate all arguments and does not stop after the first error, but rather aggregates all errors and throws an exception which message field is a dictionary with all errors found per field.

This option is very useful to avoid many roundtrips between client and server when you have a complex form or web service.

I could not find an equivalent feature in webargs, does such a feature exist? If not, it would be very nice to have and that would put webargs to par (and even better) with reqparse.

@sloria

This comment has been minimized.

Copy link
Member

commented Aug 31, 2015

"Error bundling" has not yet been implemented in webargs, though it's definitely a feature I would like to see.

One solution is to use marshmallow in tandem with webargs (I see Flask-RESTful is working towards replacing it's marshalling module in favor of marshmallow) because it does have the error-bundling you're looking for. You would use webargs solely to pull arguments off of the request, then leave validation up to marshmallow. There is even some work being done to provide tighter integration between the two libraries: https://github.com/hartror/webargs-marshmallow .

I would accept a PR implementing this feature in webargs, but for the time being, marshmallow's validation is the way to go.

@jfpoilpret

This comment has been minimized.

Copy link
Author

commented Sep 2, 2015

Thanks for the comment.
Currently I don't use marshmallow in my project as the marshalling support of Flask-RestFul fits my needs for output; I am not sure yet I would want to add it as a new dependency just for this.

I will take a look at webargs source and see if I can easily add this feature and propose a PR for it. However, I think that won't be until a few weeks more.

I will put updates here if needed.

@marcellarius

This comment has been minimized.

Copy link
Contributor

commented Sep 2, 2015

A related change that I had considered making was to catch ValidationError exceptions during parsing and ensure the arg name was set -- as validation functions probably won't know the correct arg name when raising the exception.

@sloria

This comment has been minimized.

Copy link
Member

commented Sep 27, 2015

This is solved by using marshmallow for validation.

@sloria sloria closed this Sep 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.