-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-5628): bulkWriteResult.insertedIds does not filter out _ids that are not actually inserted #3867
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
Conversation
durran
left a comment
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.
The AC on the ticket has a requirement of perf tests covering the changes. We do have perf tests covering these 2 scenarios so I don't think we need to add anything but at least a run to report what the impact is of this change would be helpful. (The script is npm run check:bench)
durran
left a comment
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.
Still missing the requested test structure changes and updated wording.
W-A-James
left a comment
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.
Just a couple quick test changes.
nbbeeken
left a comment
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.
The section of your PR body between "RELEASE_HIGHLIGHT_START" and "RELEASE_HIGHLIGHT_END" is what ends up being put in the release notes for this change.
I have a few suggestions:
-
current title:
BulkWriteResult.insertedIdsBug Fix- Let's make is a bit more descriptive as a first touch point to what is changing here. "Inserted ids in bulk write results filtered for successful insertion" (or something like that, I don't think my phrasing is ideal here 🤔)
-
current body: When invalid id(s) is/are attempted to be inserted through a
BulkWriteorInsertMany, they will no longer appearBulkWriteResult.insertedIds.- It's not only invalid id(s) right? I believe there are other possible write errors that can indicate an id was not actually inserted. If so, let's generalize the language.
- When referencing APIs it helps to match up the monospace with what users expect to see in their usages, so instead of
InsertManywe should refer to.insertMany()orcollection.insertMany()(same for.bulkWrite()).- So, in the same area of concern,
BulkWriteResult.insertedIdsshould reference precisely how users would access theinsertedIdsprop in the scenario we are changing. This probably calls for a code block where you showtry/catchinsertManyinside thecatchyou access the insertedIds however they are meant to be accessed:error.result.x.y.z.insertedIds
- So, in the same area of concern,
nbbeeken
left a comment
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.
code changes lgtm, just looking for the release highlights updates now, TIA
Description for NODE-5628
Before this change,
BulkWriteResult.insertedIds(1) would return an Object containing all attempted insertedIds, regardless of if any of the inserts failed. This affectsBulkWriteandInsertManyoperations. After this PR is merged,BulkWriteResult.insertedIdswill reflect which _ids were actually inserted.Other Notes for Reviewers
InsertManyoperation; however, I was able to reproduce it generally for any insert operation that returnsBulkWriteResultnamelyBulkWrite.BulkResult.insertedIdswill still contain unsuccessful inserted_ids. TheBulkResultclass is not user facing.BulkResult.writeErrorslist property, rather than the actual direct insert response from the server, since the batch result does not contain_idinformation.Is there new documentation needed for these changes?
Yes, it needs to be communicated to users that when an insert does not succeed through a
bulkwrite()orcollection.insertMany(), it will no longer appear in the error's.result.insertedIdsWhat is the motivation for this change?
See release highlights.
Release Highlight
Inserted ids in bulk write only contain successful insertions
Prior to this fix the bulk write error's
insertedIdsfield contained ids of all attempted inserts in a bulk operation.When a
bulkwrite()or aninsertMany()operation rejects one or more inserts, throwing an error, the error'sBulkWriteResultproperty will be filtered to only contain successfully inserted ids (ex:error.result.insertedIds).Bug Description
Previous Behavior
The error's
.result.insertedIdsdoes includes all attempted inserts, regardless of if they failed or not.New Behavior
The error's
.result.insertedIdsdoes not include unsuccessful inserts.Namely,
Checklist
npm run check:lintscripttype(NODE-xxxx)[!]: descriptionfeat(NODE-1234)!: rewriting everything in coffeescript