marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

be more verbose: marshmallow.exceptions.ValidationError: {'_schema': ['Invalid input type.']}

Open milahu opened this issue 2 years ago • 1 comments

im debugging an app that throws

marshmallow.exceptions.ValidationError: {'_schema': ['Invalid input type.']}

the problem is that marshmallow.Schema._deserialize is called like

data = OrderedDict() # is_collection(data) == False
self._deserialize(data, many = True)

to fix this, i need either data = [ OrderedDict() ] or many = False

it would be nice if the error message Invalid input type would be more helpful here

for example

# marshmallow/schema.py

        if many:
            if not is_collection(data):
                error_store.store_error([self.error_messages["type"]], index=index, detail="many but no collection")
                ret_l = []  # type: typing.List[_T]

        if not isinstance(data, Mapping):
            error_store.store_error([self.error_messages["type"]], index=index, detail="data is no Mapping")

milahu avatar Apr 17 '22 13:04 milahu

This would be incredibly helpful.

Would the project be open to a pull request that splits this into messages that include the expected type, but respects any custom error messages already defined?

mmulqueen avatar May 03 '22 17:05 mmulqueen