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

Pass through user ValidationError kwargs #418

Closed
wants to merge 1 commit into
base: dev
from

Conversation

Projects
None yet
3 participants
@russelldavies
Contributor

russelldavies commented Mar 16, 2016

I noticed that in ValidationError there is a kwargs dictionary, which seems to be for user arguments. I thought I'd use it to add a status_code kwarg so that when I catch the exception in my code I could add a bit more semantic information to the response. However, because of how the schema loading works, it is discarded.

This patch fixes this but I'm not sure it's clean enough to get merged. Perhaps a more extensive refactoring is required.

@sloria

This comment has been minimized.

Member

sloria commented Mar 19, 2016

Thanks for the PR. This is a known issue.

This issue is the likely the cause of sloria/webargs#85.

I'll test this out when I get some time.

@@ -181,6 +183,7 @@ def run_validator(self, validator_func, output,
raise ValidationError(self.default_schema_validation_error)
except ValidationError as err:
errors = self.get_errors(index=index)
self.kwargs = err.kwargs

This comment has been minimized.

@sloria

sloria Mar 19, 2016

Member

Since multiple ValidationErrors may be raised during validation, it might make sense to do self.kwargs.update(err.kwargs).

This comment has been minimized.

@russelldavies

russelldavies Mar 22, 2016

Contributor

Good point, I've updated the pull request.

@russelldavies russelldavies force-pushed the russelldavies:exception_kwargs branch from 0f0df21 to 187b1ab Mar 22, 2016

@sloria

This comment has been minimized.

Member

sloria commented Apr 4, 2016

A more complete implementation of this is in #428.

@lafrech

This comment has been minimized.

Member

lafrech commented Oct 14, 2018

@russelldavies any thoughts on #996?

@russelldavies

This comment has been minimized.

Contributor

russelldavies commented Oct 14, 2018

@lafrech I haven't used this library for a long time now so can't comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment