我得到了以下代码的意外行为:
import cerberus
v = cerberus.Validator()
schema = {'list_of_values': {'type': 'list',
'schema': {'items': [{'type': 'string', 'coerce': str},
{'type': 'integer', 'coerce': int}]}}
}
document = {'list_of_values': [['hello', 100], [123, "122"]]}
v.validate(document, schema)
v.errors我希望没有错误,因为强制应该处理类型。但我得到了
{'list_of_values': [{1: [{0: ['must be of string type'],
1: ['must be of integer type']}]}]}这是一个bug吗?我是不是误解了强制是如何工作的?
发布于 2019-03-15 20:47:43
@funky-未来
如果你有什么不对劲的地方,我确实可以通过将示例复制粘贴到提示符中来重现这个问题:
>>> import cerberus
>>> v = cerberus.Validator()
>>> schema = {'list_of_values': {'type': 'list',
... 'schema': {'items': [{'type': 'string', 'coerce': str},
... {'type': 'integer', 'coerce': int}]}}
... }
>>> document = {'list_of_values': [['hello', 100], [123, "122"]]}
>>> v.validate(document, schema)
False
>>> v.errors
{'list_of_values': [{1: [{0: ['must be of string type'], 1: ['must be of integer type']}]}]}Python3.5.2,cerberus1.2
https://stackoverflow.com/questions/53688770
复制相似问题