-
Notifications
You must be signed in to change notification settings - Fork 219
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
Any keyword halts on type exception #399
Comments
After further testing I was able to get this schema to work as expected. This was pretty unclear from the documentation as given and I would love to either submit a patch to improve the keywords or a documentation modification to make things more clear.
Any preferences? |
I haven't looked into the Any / All validators in details but if you're writing custom validators, it's possibly more clear to follow the structure here: https://github.com/alecthomas/voluptuous#validation-functions (i.e., move the responsibility of checking the type into the custom validator and let it raise from voluptuous import *
def IsUnixTimestamp(v):
if not isinstance(v, int):
raise Invalid(f"Provided value is not a Unix timestamp: {v}")
# ...
return v which gives: >>> IsUnixTimestamp('abc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in IsUnixTimestamp
voluptuous.error.Invalid: Provided value is not a Unix timestamp: abc and then wrap both validators in |
@svisser I originally was moving in that direction but the intent is to both validate and have an easy to read description of the data itself. I ended up keeping the type checks in the schema because it makes a significant difference when explaining the data structures to people. |
I have a data structure that has a
Time
field that can either be ISO-6801 timestamp or an epoch time. Unfortunately theAny
keyword isn't progressing to the second validation checks on type failure.Repro
Expectation
Any should notice the failure but not report the validation failures until the all of the validators have failed.
Exact Stack Trace
Versions
The text was updated successfully, but these errors were encountered: