Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoStore::Session is not deserialized correctly #31

Open
kliput opened this issue Aug 18, 2015 · 2 comments
Open

MongoStore::Session is not deserialized correctly #31

kliput opened this issue Aug 18, 2015 · 2 comments

Comments

@kliput
Copy link

kliput commented Aug 18, 2015

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

@brianhempel
Copy link
Owner

Is this only an issue with the older Mongo driver?

@brianhempel
Copy link
Owner

I can't reproduce this on my (admittedly newer) setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants