RUBY-3355 - Create when key '_id' (as string) is nil results in error#2808
Open
DrissTM wants to merge 1 commit intomongodb:masterfrom
Open
RUBY-3355 - Create when key '_id' (as string) is nil results in error#2808DrissTM wants to merge 1 commit intomongodb:masterfrom
DrissTM wants to merge 1 commit intomongodb:masterfrom
Conversation
…wo different _id keys in the document
Contributor
|
Thank you! I've added a Jira ticket here (https://jira.mongodb.org/browse/RUBY-3355) to track this. Thank you for finding this, and for the pull request! |
|
Hi @DrissTM thanks for filing this PR. We have tagged this for consideration next quarter and have backlogged the associated Jira ticket until then. Please follow/watch https://jira.mongodb.org/browse/RUBY-3355 for updates. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi!
While investigating an issue in an application I'm working on I discovered that trying to insert a document containing
'_id' => nilwill raise the following exception:Here's a reproduction script:
I was able to track down the issue in the
lib/mongo/operation/shared/idable.rbfile:... def id(doc) doc.respond_to?(:id) ? doc.id : (doc['_id'] || doc[:_id]) end def has_id?(doc) !!id(doc) end def ensure_ids(documents) @ids = [] documents.collect do |doc| doc_with_id = has_id?(doc) ? doc : doc.merge(_id: id_generator.generate) @ids << id(doc_with_id) doc_with_id end end ...When
'_id'is equal tonilhas_id?returnsfalsewhich causesensure_idsto generate an id that it stores in:_idbut without removing the'_id'key which results in the document having both'_id'and:_id, hence the exception mentioned above.Let me know if I should create an issue in JIRA first