marshmallow-code / marshmallow-code/marshmallow

Allow 'load_default' for required fields since they can be used with partial.

Open
#2,151 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently we are using load_default and required together for some cases where we are working with partial loading.

In this case field that is required is no longer required and should use load_default value, but it is not allowed in the code:
```
if required is True and load_default is not missing_:
raise ValueError("'load_default' must not be set for required fields.")
```

Would it make sense to allow it for such cases?

```
first_party_non_custodial_allowed = marshmallow.fields.Bool(
required=True,
load_default=True,
dump_default=True,
)
```

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 at the field initialization code containing the required and load_default validation, then trace how partial loading affects required fields. Confirm the intended behavior for the shown Bool field and identify the relevant tests before changing the validation. Done means required fields can use load_default for partial loads without breaking existing required-field behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.