marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

Simplify field overrides

Open sloria opened this issue 6 years ago • 3 comments

Class inheritance is very convenient, so it would be nice to make field inheritance just as convenient. This seems like a syntax that would be useful for extending fields in the core. fields.override(**kwargs)?

Originally posted by @deckar01 in https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues/240#issuecomment-526729498

sloria avatar Aug 31 '19 15:08 sloria

Seems like something like this could be especially convenient when used with required and allow_none.

# make all fields required by default
fields.set_defaults(required=True)

sloria avatar Aug 31 '19 15:08 sloria

As an intermediate step, we could set more defaults at the class level

fields.Field.default_required = True

sloria avatar Sep 08 '19 14:09 sloria

Just came looking for this exact functionality. I want to set the majority of fields to allow_none=True and having to go through every one makes the code quite verbose and is also time consuming. I wonder if it is better/possible to have it configured at the Schema level? Like an option in Meta?

+1 from me

awgymer avatar Aug 07 '20 02:08 awgymer