marshmallow-code / marshmallow-code/flask-smorest

Schema partial=True ignored for location="json"

Open
#525 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
717
Forks
77
Avg merge
7h 49m
Merged PRs (30d)
3

Description

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

```python
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?

Contributor guide

Open the contributing guide

Research direction

Start with the @bp.arguments decorators in the provided example, comparing the query location where partial=True works with the JSON location where it does not. Reproduce the behavior using ModelSchema(only=("parameter_schema",), partial=True) and check the JSON argument-loading path. Done means partial=True behaves consistently for JSON, or the limitation is clearly documented.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.