marshmallow-mongoengine icon indicating copy to clipboard operation
marshmallow-mongoengine copied to clipboard

BinaryField assigned to wrong marshmallow field

Open gordania opened this issue 5 years ago • 0 comments

The mongoengine validation of BinaryField makes it clear that a valid field should either be of type six.binary_type or bson.Binary.

However, the marshmallow-mongoengine conversion pushes mongoengine BinaryField data into the marshmallow Integer field. This causes data to be mis-cast and validation to fail, as in the example below.

from marshmallow_mongoengine import ModelSchema
from mongoengine import BinaryField, DynamicDocument


class ExampleModel(DynamicDocument):
    binary_data = BinaryField(null=True)


class ExampleModelSchema(ModelSchema):
    class Meta:
        model = ExampleModel

image

Since there is no corresponding "Binary" field in marshmallow, I propose the conversion be switched from Integer field to Raw field.

Doing so seems to solve my problem: image

gordania avatar Jan 09 '20 17:01 gordania