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

find(id) returns stale data with enabled identity_map and Mongoid::Versioning

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.4
    • Affects Version/s: None
    • Component/s: None

      Mongoid documents with versioning included and with enabled identity map get stale after updates.

      It goes like this:
      1) Get object.
      2) Update it.
      3) save! it.
      4) .find(id) returns old version, before update.
      It happens with Mongoid 2.3.3

      Code to reproduce:

      # connect to mongo
      Mongoid.config.identity_map_enabled
      # true
      
      class Bong
       include Mongoid::Document
       include Mongoid::Versioning
       field :session_cookie, type: String
       index :session_cookie
      end
      
      Bong.create!(session_cookie: "111")
      #<Bong _id: 4eba2d2d530a691d13000001, _type: nil, version: 1, session_cookie: "111">
      
      b = Bong.find('4eba2d2d530a691d13000001')
      #<Bong _id: 4eba2d2d530a691d13000001, _type: nil, version: 1, session_cookie: "111">
      b.session_cookie = '222'
      b.save!
      
      b = Bong.find('4eba2d2d530a691d13000001')
      #<Bong _id: 4eba2d2d530a691d13000001, _type: nil, version: 1, session_cookie: "111">
      b.session_cookie
      "111"
      
      b.versions
      #[]
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            dimaulupov dimaulupov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: