mongo_session_store
mongo_session_store copied to clipboard
MongoStore::Session is not deserialized correctly
Hello,
I try to use mongo_session_store with MongoStore. For some reasons, we are stuck with ruby mongo 1.12 driver, so lastest working version of mongo_session_store is 5.1 (6.0 does not want to work with 1.12).
I've noticed that with every request, new document in database is created. Analysing code I saw these lines:
def self.load(options = {})
options[:data] = options["data"] if options["data"]
new(options)
end
Document fetched from database with e.g. ActionDispatch::Session::MongoStore::Session.collection.find.first is: {"_id"=>"lsn4t6544ngQjAEgofn-dHlMytA", "data"=><BSON::Binary:70311184564240>, "created_at"=>2015-08-18 13:09:19 UTC, "updated_at"=>2015-08-18 13:09:19 UTC}
but using ActionDispatch::Session::MongoStore::Session.where.first, a Session instance is in form:
#<ActionDispatch::Session::MongoStore::Session:0x007fe536bc4238 @_id=nil, @data=<BSON::Binary:70311183800340>, @created_at=nil, @updated_at=nil>
Isn't it a bug, that self.load method sets only options[:data] field, ignoring _id, created_and and updated_at (whose are Strings not Symbols)?
I think it causes that Sessions can't be deleted, e.g.:
2.1.4 :096 > ActionDispatch::Session::MongoStore::Session.where.collect &:_id
=> [nil, nil, nil, nil, nil]
2.1.4 :107 > ActionDispatch::Session::MongoStore::Session.where.collect &:destroy
=> [{"ok"=>1, "n"=>0}, {"ok"=>1, "n"=>0}, {"ok"=>1, "n"=>0}, {"ok"=>1, "n"=>0}, {"ok"=>1, "n"=>0}]
Mongo session store version 6.0 has the same code for self.load.
Best regards, Jakub Liput
Is this only an issue with the older Mongo driver?
I can't reproduce this on my (admittedly newer) setup.