-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.3.3
-
Component/s: Persistence
-
None
-
(copied to CRM)
-
Fully Compatible
Given the following Parent and Child models:
class Parent include Mongoid::Document embeds_many :childs end class Child include Mongoid::Document embedded_in :parent end
Every time you run assign_attributes it sets {{delayed_atomic_sets}}, but when you assign an empty array (parent.assign_attributes(childs: [])) it does not clear {{delayed_atomic_sets}} as expected.
This causes an error on save due to conflicting operations (set and unset child) if a previous command had set {{delayed_atomic_sets}}.
Below is a reproduction of this behavior:
parent = Parent.create() 5.times { parent.childs.create() } parent.assign_attributes(childs: parent.childs.first(4)) parent.delayed_atomic_sets['childs'].length => 4 parent.assign_attributes(childs: parent.childs.first(3)) parent.delayed_atomic_sets['childs'].length => 3 parent.assign_attributes(childs: []) parent.delayed_atomic_sets['childs'].length => 3 parent.save => Updating the path 'childs' would create a conflict at 'childs' (on localhost:27017, legacy retry, attempt 1) (Mongo::Error::OperationFailure)
- causes
-
MONGOID-5352 Fix assign_attributes on replacing embeds_many
- Closed
- links to