marshmallow-code / marshmallow-code/marshmallow
Why is post_load called after schema.validate()?
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
Hello,
I noticed that @post_load is called when calling schema_object.validate().
Then I went to the library code and saw this (everything seemed OK, because I was getting a feeling postprocessing will not take a place):

It was obvious I will need some debugging, so I went through the calling stacktrace and got surprised when I saw the `marshalling` module calls the `deserialize` method which calls `schema_object.load()`. I don't think it is expected to have `post_load` called when you call `schema_object.validate()`, because in my case, we are performing some intensive operations, e.g. b64 decoding some string data and it takes some time. In this way, we have `post_load` called twice - the first time when a controller validates the input and the other when we actually load the data into a dict.
Of course, this is not a bug, but an open question.
Contributor guide
Research direction
Start by tracing the schema_object.validate() and schema_object.load() entry points through the marshalling module and its deserialize method. Determine whether post_load is intentionally invoked during validation, then document the expected lifecycle and whether the behavior should be avoided or changed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100