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

Closed
ParthGandhi opened this issue Jan 22, 2016 · 2 comments
Closed

Unused status_code field in ValidationError? #85

ParthGandhi opened this issue Jan 22, 2016 · 2 comments
Labels

Comments

@ParthGandhi
Copy link

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)

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

if __name__ == '__main__':
    app.run('0.0.0.0', debug=True)

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

@sloria
Copy link
Member

sloria 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
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 as completed in #97 Apr 4, 2016
@lafrech
Copy link
Member

lafrech commented Oct 14, 2018

@ParthGandhi any thoughts on marshmallow-code/marshmallow#996?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants