I have a simple problem and am unsure the best way to handle it. I have a schema defined as follows:
class MySchema(Schema):
title = fields.String(required=True)
imageUrl = fields.Url()
imageUrl
is an optional field, sometimes it will be None/null. If this happens, it's ok and it doesn't need to be a valid url. But I when I do:
my_schema.load(request.get_json())
on incoming data that is PUT, the url field records an error: Field may not be null.
I thought using partial=True
in the call to load would work, but it doesn't. I also didn't like that because this isn't a partial, it's the full object, it just so happens some of my fields are nullable in the DB.
How do I get marshmallow to validate the imageUrl when it is non-null, but to ignore it when it is null?