Skip to content

Schema validation of mandatory fields on a blueprint with a HTTP PATCH method containing only modified fields #628

Description

@juur

I have a simple CRUD class (based on flask.views.MethodView).
The Schema class is based on marshmallow_sqlalchemy.SQLAlchemyAutoSchema.

 @_bp.arguments(AccountGroupModelSchema)
 @_bp.response(200, AccountGroupModelSchema)
 def patch(self, updated, account_group_id):
     """Update an existing object."""
     item = AccountGroup.query.get_or_404(account_group_id)

     item.name = updated.name or item.name

     db.session.commit()
     return item

When submitting a HTTP PATCH, the JSON payload contains only those fields being modified, e.g. { "name": "new_name" }. This means the Schema validation fails, because mandatory fields are not present.

Is there anyway to handle validating the fields that are present AND rejecting any fields that are unknown but NOT failing validation for missing (as not being modified) fields in a PATCH? Or do I just have to take the JSON directly, update the entity, then validate prior to updated in the ORM?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions