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

set default value for _update when no update object is provided and versionKey is set to false #13795

Merged

Conversation

MohOraby
Copy link
Contributor

Summary

Fixes #13783

When calling findOneAndUpdate with no update query the _decorateUpdateWithVersionKey function adds '$setOnInsert': { __v: 0 } to the update doc so it passes the _mergeUpdate first check which then sets the _update to {} but with versionKey set to false the update doc length is 0 so the _mergeUpdate function returns early

this PR set a value of empty object to the _update property even when Object.keys(doc).length === 0 so it's defined

valeriuflorescu16

This comment was marked as outdated.

test/model.findOneAndUpdate.test.js Outdated Show resolved Hide resolved
lib/query.js Outdated Show resolved Hide resolved
MohOraby and others added 3 commits August 30, 2023 19:26
Co-authored-by: Valeriu-Andrei Florescu <49231993+valeriuflorescu16@users.noreply.github.com>
Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 👍

@MohOraby MohOraby changed the title set default value for _update when no update object is provided and v… set default value for _update when no update object is provided and versionKey is set to false Aug 31, 2023
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@vkarpov15 vkarpov15 merged commit d448894 into Automattic:master Sep 1, 2023
@vkarpov15 vkarpov15 added this to the 7.5.1 milestone Sep 1, 2023
@MohOraby MohOraby deleted the fix/findOneAndUpdate-no-update-object branch September 1, 2023 18:43
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.

Issue when using _findOneAndUpdate with empty update
4 participants