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.
In cases where you tried to save a
Document
with a field containing aLink
/DBRef
instead of the wrapped object itself, thevalidate_on_save
hook would stop working, and return an error.This was because the Link object was first serialized into a dict, and any further validation with
Link.validate
would always fail trying to deserialize a dict like{"id": ..., "collection": ...}
as a real Document rather than a Link.I've committed a simple solution, however, you can refine it to make it more elegant.
As my reserch has shown, there is no sense tweaking the way
Document.validate_self
validates the document. Instead, the easiest way would be to teach theLink
to recognize its own schema.This approach has the only obvious corner case: if the user creates a custom model with the same structure as Link, and then tries to wrap it with Link, he would get an unexpected behavior.