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

Unused `status_code` field in `ValidationError`? #85

ParthGandhi opened this issue Jan 22, 2016 · 2 comments


Copy link

commented Jan 22, 2016

I'm trying to figure out how to return specific status codes from validation errors. Looks like it always returns a 422, ignoring whats specified in the ValidationError.

from flask import Flask
from webargs import fields, ValidationError
from webargs.flaskparser import use_args

app = Flask(__name__)

def dummy_validator(val):
    raise ValidationError(message="Error!", status_code=500)

@use_args({'test_field': fields.String(validate=dummy_validator)})
def hello_world(args):
    return 'Hello World!'

if __name__ == '__main__':'', debug=True)

Then: curl -v http://localhost:5000?test_field=hello returns 422 Unprocessable Entity instead of 500 Internal Server Error.


This comment has been minimized.

Copy link

commented Jan 26, 2016

This is a known bug. Since marshmallow catches ValidationErrors, collects and formats them, then reraises a new ValidationError, there is currently no way to use the status_code attribute in a webargs Parser's error_callback.

I welcome any help and ideas on how to address this.

@sloria sloria added the bug label Jan 26, 2016

sloria added a commit to marshmallow-code/marshmallow that referenced this issue Apr 4, 2016

Pass ValidationError kwargs through all instantiations
This is to address issues like marshmallow-code/webargs#85, where additional arguments
may be passed to ValidationError. These additional arguments
should be passed when marshmallow reraises ValidationErrors

@sloria sloria closed this in #97 Apr 4, 2016


This comment has been minimized.

Copy link

commented Oct 14, 2018

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