marshmallow-code / marshmallow-code/marshmallow
Consistency with allow_none with serialization and deserialization
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
I saw already comments how to workaround this issue:
https://github.com/marshmallow-code/marshmallow/issues/229#issuecomment-363250656
https://github.com/marshmallow-code/marshmallow/issues/229#issuecomment-134387999
But still I would like to marshmallow to be consistent with itself.
Basically you have a schema with allow_none=False and after dumping it you cannot load it back (without manually fixing the output that is not correct according to schema).
```
import marshmallow
class TransferSchema(marshmallow.Schema):
id = marshmallow.fields.Int(allow_none=False)
str = marshmallow.fields.Str(allow_none=False)
x = TransferSchema()
dumped = x.dump({
'id': None,
'str': None,
})
print(dumped)
loaded = x.load(dumped)
print(loaded)
```
error:
```
marshmallow.exceptions.ValidationError: {'id': ['Field may not be null.'], 'str': ['Field may not be null.']}
```
I think allow_none should be respected for both on serialize and deserialize.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided TransferSchema example and trace how allow_none is handled during dump and load for the Int and Str fields. Confirm the intended behavior against the linked issue discussions, then add or update coverage so serialization and deserialization treat null values consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100