schema.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:fleaker 作者: croscon 项目源码 文件源码
def invalid_fields(self, data, original_data):
        """Validator that checks if any keys provided aren't in the schema.

        Say your schema has support for keys ``a`` and ``b`` and the data
        provided has keys ``a``, ``b``, and ``c``. When the data is loaded into
        the schema, a :class:`marshmallow.ValidationError` will be raised
        informing the developer that excess keys have been provided.

        Raises:
            marshmallow.ValidationError: Raised if extra keys exist in the
                passed in data.
        """
        errors = []

        for field in original_data:
            # Skip nested fields because they will loop infinitely
            if isinstance(field, (set, list, tuple, dict)):
                continue

            if field not in self.fields.keys():
                errors.append(field)

        if errors:
            raise ValidationError("Invalid field", field_names=errors)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号