-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix: mongoose schema default should not mutate original object #12114
Conversation
I dont like spread operator here. Use clone if you need to create an immutable operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use our internal clone method.
@Uzlopak With |
If you claim that you dont want to mutate the schema then you have to deepclone. Or else it is still mutating something. |
@Uzlopak The schema should be mutated, the problem is that the current implementation is mutating the original object by adding the default nested properties. |
$applyDefaultsToNested(path[key], prefix + key, this); | ||
this.$set(prefix + key, path[key], constructing, Object.assign({}, options, { _skipMarkModified: true })); | ||
// Create a copy of the object to avoid editing the original | ||
const pathKey = utils.clone(path[key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this change, it seems unnecessarily heavy from a performance perspective. I think we'd just need to refactor and be smarter about setting defaults on the nested path without setting them on the input parameter. We'll take a look and see if we can come up with an alternative solution. I agree this is a bug, I just don't think the solution is ideal.
Closes #12102