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

Removed text 'for dictionary value' from the validation message for dict #18

Closed
wants to merge 1 commit into from
Closed

Conversation

rwieckowski
Copy link
Contributor

Removed additional text for messages created during dictionary validation to provide consistent messages with other schema types and clean user defined messages.

Now the user defined messages are not polluted with additional text.
Following code:

import voluptuous as v
validate = v.Schema({'one': msg('two', 'should be "two"')})
validate({'one': 'three'})

gives us

Traceback (most recent call last):
...
InvalidList: should be "two" @ data['one']

instead of

Traceback (most recent call last):
...
InvalidList: should be "two" for dictionary value @ data['one']

@alecthomas
Copy link
Owner

This text was explicitly chosen because without it the error message can be ambiguous, so I prefer not to merge as-is.

I wouldn't be opposed to a Schema-level option to enable this behaviour, though there are a bunch more places that need to be changed to make this consistent. For example, list/tuple validators have the same form and would also need to be updated.

Feel free to reopen this or send through another pull request if you continue.

@alecthomas alecthomas closed this Jan 6, 2013
@rwieckowski
Copy link
Contributor Author

The problem is with dictionaries where returned message is concatenated with additional text. That text shows in my user-defined message, so I don't have full control on its final form.
Is the path not good enought to determine error location in case od dictionaries?

In case of list/tuples you doesn't have message concatenation so user-defined messages works fine here.

import voluptuous as v
validate = v.Schema(['one'])
validate(['two'])

gives us

Traceback (most recent call last):
...
InvalidList: invalid list value @ data[0]

And with user-defined message

import voluptuous as v

validate = v.Schema(v.msg(['one'], 'should be "one"'))
validate('two')

gives us (which is correct)

Traceback (most recent call last):
...
InvalidList: should be "one"

Also check example in the pull request which shows why the dictionary behaviours differently.

jd added a commit to jd/voluptuous that referenced this pull request Dec 22, 2017
This allows any validator to be compiled by implementing the
__voluptuous_compile__ method.

This avoids having voluptuous.Any and voluptuous.All defining new Schema for
sub-validators: they can be compiled recursively using the same parent schema.

This solves the recursive Self case.

Fixes alecthomas#18
jd added a commit to jd/voluptuous that referenced this pull request Dec 24, 2017
This allows any validator to be compiled by implementing the
__voluptuous_compile__ method.

This avoids having voluptuous.Any and voluptuous.All defining new Schema for
sub-validators: they can be compiled recursively using the same parent schema.

This solves the recursive Self case.

Fixes alecthomas#18
alecthomas pushed a commit that referenced this pull request Dec 26, 2017
* Allow to use nested schema

This allows to refer to the current schema using voluptuous.Self and have
nested definitions.

Fixes #128

* Allow any validator to be compiled

This allows any validator to be compiled by implementing the
__voluptuous_compile__ method.

This avoids having voluptuous.Any and voluptuous.All defining new Schema for
sub-validators: they can be compiled recursively using the same parent schema.

This solves the recursive Self case.

Fixes #18
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.

2 participants