Inconsistant behavior when using partial schema
TheBigRoomXXL opened this issue · comments
I have an API made with flask-smorest with to following endpoint :
@blp.route('/')
class BinRessource(MethodView):
@blp.arguments(PartialBinSchema , location="querystring")
@blp.response(200, BinSchema(many=True))
def get(self, filters):
"""List bins"""
return Bin.auth_query(**filters)
@blp.arguments(BinSchema(many=True))
@blp.response(201, BinSchema(many=True))
def post(self, new_bin_list):
"""Add a list of new bin"""
list_bins = [Bin(**new_bin) for new_bin in new_bin_list]
db.session.add_all(list_bins)
db.session.commit()
return list_bins
class PartialBinSchema(BinSchema):
class Meta:
partial=True
The generated schema is invalid because the fields are still required (see the red *):
I can fix that by replacing PartialBinSchema
with BinSchema(partial=True)
which give me the following result:
That way the generated schema is valid but the name is not as clear and trigger a warning because there is two schemas resolving to the name Bin.
Regardless of the naming problem I would expect (partial=True)
and class Meta: partial=True
to generate the same schema.
I just checked, you can't pass partial
as meta param in marshmallow.
PartialBinSchema
is the same as BinSchema
since partial
in Meta
is ignored.
This might be a feature request for marshmallow but not an issue in apispec.