-
Couldn't load subscription status.
- Fork 220
Open
Description
I have a data structure that has a Time field that can either be ISO-6801 timestamp or an epoch time. Unfortunately the Any keyword isn't progressing to the second validation checks on type failure.
Repro
from voluptuous import All, Any, Schema
from voluptuous.humanize import validate_with_humanized_errors
# We won't get to the custom validators in the repro
from custom_validators import IsUnixTimestamp, TimezoneSTRToUTCDatetime
test_data = "2019-01-30 13:04:41.000"
test_schema = Schema(Any(All(int, IsUnixTimestamp), All(str, TimezoneSTRToUTCDatetime()))
validate_with_humanized_errors(test_data, test_schema)
Expectation
Any should notice the failure but not report the validation failures until the all of the validators have failed.
Exact Stack Trace
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 267, in __call__
return self._compiled([], data)
File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 204, in _run
return self._exec(self._compiled, value, path)
File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 256, in _exec
self.msg, path=path)
File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 249, in _exec
return func(path, v)
File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 204, in _run
return self._exec(self._compiled, value, path)
File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 286, in _exec
raise e if self.msg is None else AllInvalid(self.msg, path=path)
File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 284, in _exec
v = func(path, v)
File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 804, in validate_instance
raise er.TypeInvalid(msg, path)
voluptuous.error.TypeInvalid: expected int
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/voluptuous/humanize.py", line 38, in validate_with_humanized_errors
return schema(data)
File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 271, in __call__
raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: expected int
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "repro.py", line 10, in <module>
validate_with_humanized_errors(test_data, test_schema)
File "/usr/local/lib/python3.7/site-packages/voluptuous/humanize.py", line 40, in validate_with_humanized_errors
raise Error(humanize_error(data, e, max_sub_error_length))
voluptuous.error.Error: expected int. Got '2019-01-30 13:04:41.000'
Versions
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
Python==3.7.2
voluptuous==0.11.5
Metadata
Metadata
Assignees
Labels
No labels