Why is post_load called after schema.validate()?
See original GitHub issueHello,
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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (8 by maintainers)
Top GitHub Comments
I was able to repro on 3.2.0. Here is a minimal repro case:
This is an artifact of validation calling
_do_load
under the hood. Propagatingpostprocess
through the field load calls would work, but this might be a good opportunity to consider separating validation from loading. There has been recurring interest in validating objects that have already been deserialized.It doesn’t seem to be called in marshmallow 2 or 3.
If
post_load
was being called duringvalidate
it would be a bug. I can’t reproduce that behavior.