Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Link validation #714

Merged
merged 5 commits into from
Oct 12, 2023
Merged

Conversation

iterlace
Copy link
Contributor

@iterlace iterlace commented Sep 18, 2023

In cases where you tried to save a Document with a field containing a Link/DBRef instead of the wrapped object itself, the validate_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 the Link 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.

@iterlace
Copy link
Contributor Author

Ping?

@roman-right
Copy link
Member

Hi! Sorry for the delay. Thank you for the PR!
I'll check it by the end of this week

@roman-right roman-right merged commit 549aa8c into BeanieODM:main Oct 12, 2023
21 checks passed
@roman-right
Copy link
Member

Merged! Thank you! It will be published by the end of this week with others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants