Set MA_BASE_SCHEMA_CLS in Document / EmbeddedDocument #263
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.
This changes allows to set a base marshmallow schema class in the
Document
/EmbeddedDocument
template.It removes the complicated logic used to pass schema parameters (
check_unknown_fields
,meta
,params
) along theas_marshmallow_schema
/as_marshmallow_field
calls.The former implementation passing params allows twisted cases like passing a specific parameter to a schema deeply nested in the document when calling
as_marshmallow_schema
, but in a way that is absolutely not practical: it takes a hugs unreadable dict as input.In real life, schema parameters such as
unknown
are most often the same for all the application, so it makes sense to factorize them in a base schema.Corner cases can always be addresses with this implementation. It might be a little bit more cumbersome, but it should be feasible and even more readable.
This PR also fixes the cache in
as_marshmallow_schema
that was broken in 3.0.0beta. The fix is in the first commit (set meta unknown in cache modifiers) but is obsoleted by subsequent commits.