Allow use of Schema hooks on OneOfSchema #130
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: this change is very mildly backwards-incompatible, but since 3.0 is coming up for this lib, I think it's okay.
Rather than overriding the
dump()
andload()
methods of the Schema class, override_serialize
and_deserialize
, which are the "concrete" steps in schema loading and dumping which handle loading or dumping on a field-by-field basis.This still uses load() and dump() methods of the type schemas being used, but it happens between the various hooks which may run on the OneOfSchema instance.
Add a test that checks that a
post_dump
hook to remove thetype
field works.The most significant downside of this change is that it makes use of several private APIs within marshmallow. Not only are
_serialize
and_deserialize
private methods, but the error_store object which is used here is also considered private (per marshmallow docs).In order to better guarantee behavior near-identical to marshmallow, several methods from marshmallow.utils have been copied in-tree here.
One notable API change here is that arbitrary keyword arguments are no longer being passed from
OneOfSchema.load()
andOneOfSchema.dump()
down into the type schemas' load and dump methods. As a result, you cannot specify a load or dump parameter here and expect it to take effect.With the switch to overriding
_serialize
and_deserialize
, there is no practical way to pass parameters like that.closes #4