marshmallow
marshmallow copied to clipboard
Override _schema
_schema is used to store schema level errors, if we know what the schema is called why do we use _schema
from marshmallow import Schema, fields
class UserSchema(Schema):
name = fields.String()
email = fields.Email()
created_at = fields.DateTime()
class BlogSchema(Schema):
title = fields.String()
authors = fields.List(fields.Nested(UserSchema))
BlogSchema().load("""{"title":"mark", "authors":3}""")
ValidationError: {'_schema': ['Invalid input type.']}
Why doesn't it instead say
ValidationError: {'Blog.authors': ['Invalid input type.']}
I know this is a design decision but it seems weird, especially since you cannot override marshmallow.exceptions.SCHEMA
I think the error you get is at Blog schema level. Because you pass a string, not a dict. If the error was at authors field level, you'd get what you expect.