forked from marshmallow-code/marshmallow-oneofschema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use of Schema hooks on OneOfSchema
Rather than overriding the `dump()` and `load()` 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 the `type` 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()` and `OneOfSchema.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 marshmallow-code#4
- Loading branch information
Showing
2 changed files
with
107 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters