You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)defpatch(self, updated, account_group_id):
"""Update an existing object."""item=AccountGroup.query.get_or_404(account_group_id)
item.name=updated.nameoritem.namedb.session.commit()
returnitem
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?
The text was updated successfully, but these errors were encountered:
Whilst partial=True does permit PATCH to work with validation, it creates another problem within apispec causing errors like this to appear:
apispec/ext/marshmallow/openapi.py:135: UserWarning: Multiple schemas resolved to the name Account. The name has been modified. Either manually add each of the schemas with a different name or provide a custom schema_name_resolver.
I assume this is because apispec considers the partial Schema to be different to the non-partial one.
Therefore I'm back in the situation where just sending a single field in a PATCH doesn't work perfectly.
I have a simple CRUD class (based on
flask.views.MethodView
).The Schema class is based on
marshmallow_sqlalchemy.SQLAlchemyAutoSchema
.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?
The text was updated successfully, but these errors were encountered: