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

Improve colander schema error message handling #47

Merged
merged 2 commits into from Apr 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions cornice/validators.py 100644 → 100755
Expand Up @@ -34,14 +34,14 @@ def _validate_fields(location, data):
request.errors.add(location, attr.name,
"%s is missing" % attr.name)
else:
if not attr.name in data:
request.validated[attr.name] = attr.missing
continue
try:
deserialized = attr.deserialize(data[attr.name])
if not attr.name in data:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not remove the request.validated[attr.name] = attr.missing, it's part of the API and shound not be changed. Is there any reason why you're removing it?

Copy link
Author

Choose a reason for hiding this comment

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

From my point of view, the SchemaNode deserialize() method does the same thing in the right way.
"missing" case is matched with deserialized = attr.deserialize(None)

Moreover, deserialize() populate the error message with values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right. Works for me then, sounds a better way to deal with validation errors. Sounds weird to put something missing in "validated" anyway.

Thanks again for the contribution.

deserialized = attr.deserialize(None)
else:
deserialized = attr.deserialize(data[attr.name])
except Invalid, e:
# the struct is invalid
request.errors.add(location, attr.name, e.msg)
request.errors.add(location, attr.name, e.asdict()[attr.name])
else:
request.validated[attr.name] = deserialized

Expand Down