-
Notifications
You must be signed in to change notification settings - Fork 76
Description
As an example (modified from the documentation sample code):
class PetSchema(ma.Schema):
id = ma.fields.Int(dump_only=True)
name = ma.fields.String()
class PetQueryArgsSchema(ma.Schema):
name = ma.fields.String(required=False)
blp = Blueprint(
"pets", "pets", url_prefix="/pets", description="Operations on pets"
)
@blp.route("/<pet_id>")
class PetsById(MethodView):
@blp.arguments(PetQueryArgsSchema, location="query")
@blp.response(200, PetSchema)
def get(self, pet_id, query_args):
ps = PetSchema()
ps.id = 1
ps.name = f"pet_id: {pet_id}, query_args: {query_args}"
return psIntuitively, I would expect the PetsById.get method to populate with the pet_id as the first positional argument, followed by the query_args as a dictionary. It turns out it doesn't really work like this. In fact, it doesn't really work at all. This produces a TypeError as a result of mulitple arguments for 'pet_id'.
I found these other discussions: #219, #220, related to this issue, but I'm not sure if there were any conclusions drawn as to what the behavior here should, ideally, look like. For some context, my interest is in constructing an endpoint with a mandatory path argument, but a set of optional filtering values passed in the query. That behavior does not appear to be supported by blueprint argument decorators, however. That said, I suppose I'm ultimately asking is this either, 1) a bug in how flask-smorest handles these argument combinations, or 2) simply an unsupported feature that could perhaps be clarified by updates to the documentation?