marshmallow-code / marshmallow-code/marshmallow

Remove `only`, `exclude`, `many`, and `unknown` parameters of `Nested` and require callables to return Schema instances

Open
#2,794 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backwards incompat feedback welcome
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

Proposing the following 2 changes to `fields.Nested`:

(1) drop support for passing callables that return schema classes and dicts (e.g. `lambda: CSchema`) and only support callables that return instances (`lambda: CSchema()`).

**Before:**

```python
nested: (
Schema
| SchemaMeta
| str
| dict[str, Field]
| typing.Callable[[], Schema | SchemaMeta | dict[str, Field]]
),
```

**After:**

```python
nested: (
Schema | SchemaMeta | str | dict[str, Field] | typing.Callable[[], Schema]
),
```

And (2) deprecate the `only`, `exclude`, `many`, and `unknown` parameters of `Nested`.

Final end state of `fields.Nested` would be

```python
def __init__(
self,
nested: (
Schema | SchemaMeta | str | dict[str, Field] | typing.Callable[[], Schema]
),
**kwargs: Unpack[_BaseFieldKwargs],
):
```

## Why?

It would vastly both the usage and the internal implementation of `Nested`. This eliminates a class of bugs where the `nested` argument conflicts with `only`, `exclude`, `many`, and `unknown`.

See https://github.com/marshmallow-code/marshmallow/issues/2165 for an example of this.

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 locating fields.Nested and reviewing the conflicting behavior described in issue #2165. Trace its handling of callable return values and the only, exclude, many, and unknown parameters, then inspect related tests or usages. Done means the deprecation and callable contract are implemented consistently with coverage for the final API.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
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.