marshmallow-code / marshmallow-code/flask-smorest

Inject constructed arguments schema into view method

Open
#514 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
717
Forks
77
Avg merge
7h 49m
Merged PRs (30d)
3

Description

Using this example from the documentation:
```
@blp.arguments(PetQueryArgsSchema, location="query")
```
The `arguments` decorator will make sure the results of the PetQueryArgsSchema are injected into the wrapped view method, but the schema object is thrown away once finished with.

It would be very useful to also optionally inject the constructed schema object as well, since I have quite a few schemas that set internal context that is required in subsequent processing.

Marshmallow schemas have a similar thing when doing their own `@post_dump` etc decorators where you can use `pass_orig` to get at the original data before the schema processed it. I suggest we have a `pass_schema` to add an extra `schema=` kwarg to the wrapped method.

It's possible that this needs to happen in the webargs `use_args` function and not here, but I thought I'd gather opinions on this enhancement before attempting a fix myself.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the blp.arguments decorator into the webargs use_args function, as the issue suggests; no specific repository files or tests are named. Determine how an optional pass_schema setting could expose the constructed schema while preserving current injection behavior, then verify the existing arguments flow and add coverage for the new option.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.