首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Cerberus 1.3.2中排除问题

在Cerberus 1.3.2中排除问题
EN

Stack Overflow用户
提问于 2020-05-29 19:47:50
回答 1查看 100关注 0票数 0

我是Cerberus的新手,最近将Cerberus版本从1.1升级到了1.3.2。但是得到了验证错误。请查找验证架构。

代码语言:javascript
复制
my_schema = 
{
    'email': {
        'type': 'string', 'maxlength': 1000,
        'regex': EMAIL_PATTERN, 'required': True
    },
    'guest': {
        'type': 'boolean', 'required': False,
        'excludes': ['password', 'issue_password_reset']
    },
    'password': {
        'type': 'string', 'minlength': 9, 'required': True,
        'excludes': 'issue_password_reset'
    },
    'prefix': {
        'type': 'string', 'nullable': True,
        'required': False, 'maxlength': 10
    },
    'first_name': {
        'type': 'string', 'nullable': True,
        'required': False, 'maxlength': 50
    },
    'last_name': {
        'type': 'string', 'nullable': True,
        'required': False, 'maxlength': 50
    },
    'phone_number': {
        'type': 'string', 'required': False,
        'nullable': True, 'regex': PHONE_NUMBER_PATTERN
    },
    'birthday': {
        'type': 'string', 'required': True,
        'excludes': 'is_legal_drinking_age'
    },
    'is_legal_drinking_age': {
        'type': 'boolean', 'required': True,
        'excludes': 'birthday'
    },
    'issue_password_reset': {
        'type': 'boolean', 'required': True,
        'excludes': 'password'
    },
}

data = {
        "email": "guest123@email.com",
        "guest": True,
        "birthday": "1975-05-05",
        "prefix": "Ms.",
        "first_name": "Allison",
        "last_name": "Smith",
        "phone_number": "(212) 555-2002"
    }

valid = Validator(default_schema)
resp = valid.validate(data)
print(valid.errors)
print(resp)

对于Cerberus版本1.3.2,获取错误

对于Cerberus 1.1版,验证工作正常。

希望能找到一些帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-06-15 04:47:17

正如here所指出的,这种行为是正确的,因为文档不包含按要求定义的字段。返回的错误指出了这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62085269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档