marshmallow-code / flask-smorest

DB agnostic framework to build auto-documented REST APIs with Flask and marshmallow
https://flask-smorest.readthedocs.io
MIT License
651 stars 72 forks source link

Schema partial=True ignored for location="json" #525

Open Anti-Distinctlyminty opened 1 year ago

Anti-Distinctlyminty commented 1 year ago

I am attempting to have an option JSON body, but the user of partial does not work when location="json"

bp = Blueprint(...)

@bp.route("")
class ModelsResource(MethodView):
    @bp.response(HTTPStatus.OK, ModelSchema)
    @bp.arguments(
        ModelSchema(exclude=("model_id", "parameter_schema"), partial=True),   # Partial works
        location="query",
        as_kwargs=True,
    )
    @bp.arguments(
        ModelSchema(only=("parameter_schema",), partial=True), # Partial does *not* work
        location="json",
        as_kwargs=True,
    )
    def put(self, **kwargs):
        result = db.session.scalar(
            sqlalchemy.insert(Model).values(**kwargs).returning(Model)
        )
        db.session.commit()
        return result

Am I doing something incorrect in the above example?

lafrech commented 2 months ago

I don't think you're doing anything wrong.

This does sound like a bug. But I'd be surprised if this had been overlooked in webargs.