marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

Help understanding how to set Schema meta options when using Schema.from_dict()

Open prowler0305 opened this issue 1 year ago • 1 comments

I have tried searching for this answer for a while and only keep coming across how to use the from_dict() method which is great for dynamically adding fields at runtime.

However I have not figured out how to set options like ordered or unknown when using this method as the from_dict() generates a GeneratedMeta class object that has the defaults for all the options. I can't figure out how to alter those as part of creating a dynamic Schema with the from_dict() approach.

I'm assuming I'm missing something obvious if someone could point me in the right direction.

prowler0305 avatar Aug 08 '24 22:08 prowler0305

you could create a Schema subclass that sets the meta options, like so

class DynamicSchema(Schema):
    class Meta:
        dateformat = "rfc"

DynamicSchema.from_dict(...)

sloria avatar Aug 12 '24 21:08 sloria