marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

Add ability to set partial default in Meta class

Open npalmius opened this issue 2 years ago • 2 comments

It doesn't seem to be possible to configure a default partial property in the Meta class. Is there a reason for this?

It would be nice to be able to follow a pattern as follows:

class InsertSchema(Schema):
    class Meta:
        unknown = EXCLUDE

    id = fields.UUID(required=False)
    name = fields.Str(required=True)
    description = fields.Str(required=True)

class UpdateSchema(InsertSchema):
    class Meta(InsertSchema.Meta):
        exclude = ["id"]
        partial = True

The exclude in Meta works as expected, but the partial does not. I'm also using flask_smorest, so of course I can define this at the request level, e.g.

@blueprint.arguments(UpdateSchema(partial=True))

but it would be nice to be able to define it at the class-level, especially if the partial configuration is more complex and perhaps the schema is used in multiple places.

npalmius avatar Feb 17 '23 09:02 npalmius

Also interested in this feature.

Particularly since it is not possible to use MySchema and MySchema(partial=True) without getting a naming collision with flask-sqlalchemy.

zedrdave avatar Aug 14 '23 16:08 zedrdave

I guess partial was meant to be an instance parameter, but I see no objection to making it a class parameter.

Is someone willing to investigate and contribute the change?

lafrech avatar Sep 10 '23 19:09 lafrech