marshmallow-code / marshmallow-code/flask-smorest
Schema for path-arguments duplicates input
- Dominant language
- Python
- Stars
- 717
- Forks
- 77
- Avg merge
- 7h 49m
- Merged PRs (30d)
- 3
Description
Using a schema to validate/process the path arguments seems to pass the argument twice.
The data-dict of the marshmallow schema is passed as an argument and the value is passed as keyword-argument (probably by vanilla flask).
Note: This can be prevented by passing `as_kwargs = True` to the decorator
Code-Example:
```python
from flask.views import MethodView
from marshmallow import Schema
from marshmallow.fields import String
from flask_smorest import Blueprint
bp = Blueprint("pets", "pets", description="pet related operations", url_prefix="/api/pets")
class PetIdSchema(Schema):
pet_id = String(required=True)
@bp.route("/")
class SinglePet(MethodView):
"""route for operations on a single pet"""
@bp.arguments(PetIdSchema(), location="path")
def get(self, *args, **kwargs):
"""get information on this pet"""
print(f"args: {args} | kwargs: {kwargs}")
# prints: args: ({'pet_id': '600aed28e65f74c3a97f6f58'},) | kwargs: {'pet_id': '600aed28e65f74c3a97f6f58'}
pet_id = args[0]
return Pet.get_by_id(pet_id)
```
Contributor guide
Research direction
Start with the bp.arguments decorator and its handling of location="path" on Flask MethodView methods. Reproduce the example and compare the positional schema data with the keyword path argument, noting the as_kwargs=True behavior. Done means the path value is not unexpectedly supplied twice while existing decorator usage remains compatible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100