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)
评论列表
文章目录