Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5810

Cloning documents aren't working correctly in v8.0.8 using legacy attributes

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Attributes
    • None
    • Ruby Drivers

       

      #!/usr/bin/env ruby
      require 'bundler/inline'
      gemfile do
        source 'https://rubygems.org'
        gem 'mongoid', '8.0.8'
      end
      require 'mongoid'
      Mongoid.configure do |config|
        config.clients.default = { hosts: ['localhost'], database: 'test' }
        config.legacy_attributes = false
      end
      puts Mongoid::VERSION
      puts Mongo::VERSION
      
      class Purse
        include Mongoid::Document
        field :brand, type: String
        embedded_in :person
      end
      class Person
        include Mongoid::Document
        include Mongoid::Attributes::Dynamic
        field :name, type: String
        embeds_many :purses, store_as: :ps
      end
      p = Person.new(ps: [{}])
      p.save
      person = Person.find(p.id)
      before_document = person.as_document.dup
      person.purses.first.brand = "Gucci"
      after_document = person.as_document
      puts "Before_document:"
      pp before_document # expects this to not include Gucci since it was cloned before the document was updated
      puts "After_document:"
      pp after_document
      

      In v7.5.4 with legacy_attributes enabled, cloning works fine and shows the correct differences between the two documents. After v8.0.8 upgrade, we discovered that cloning will only work as expected with legacy_attributes disabled. I believe the regression happened after this change - https://github.com/mongodb/mongoid/pull/5153

       

       

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            kokchun.lim@braze.com Joe Lim
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: