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

Pass through user ValidationError kwargs #418

Closed

Conversation

russelldavies
Copy link
Contributor

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
Copy link
Member

sloria commented Mar 19, 2016

Thanks for the PR. This is a known issue.

This issue is the likely the cause of marshmallow-code/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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I've updated the pull request.

@sloria
Copy link
Member

sloria commented Apr 4, 2016

A more complete implementation of this is in #428.

@lafrech
Copy link
Member

lafrech commented Oct 14, 2018

@russelldavies any thoughts on #996?

@russelldavies
Copy link
Contributor Author

@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants