Conversation
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.
Description
A persisted embedded document can write a nested association to the wrong place when one
attributes=call builds a newembeds_onechild.The new child is built before it is attached to its parent. If it has a nested
embeds_many, that association records a delayed atomic set with a path relative to the child. When the root document builds its update, it also includes that delayed set.With different stored names, the nested array can appear as an unintended field on the root document. With the same stored name, it can be merged into the root array or produce a MongoDB path conflict.
Root cause
EmbedsOne::Buildable#buildcreates a new child without parent or association metadata. The child therefore cannot calculate a path from the root document.The
embeds_manybatch path already supplies that metadata and clears delayed sets for newly collected children. The problem occurs on theembeds_onepath.Fix
Batchable#add_atomic_setsnow records delayed atomic sets only when the base document is persisted. A new embedded document is written as part of its parent document, so a delayed set for one of the new child associations is redundant.Tests
The integration spec uses public
attributes=, nested attributes, and save APIs. It covers:embeds_onechild.Verification
bundle exec rake cicompletes every test group with 0 failures.https://jira.mongodb.org/browse/MONGOID-5999