This project is archived and is in readonly mode.
rails 2.3 session_options[:id] problem
Reported by Boban | March 17th, 2009 @ 11:16 AM | in 3.0.2
I've updated my rails project to work with rails 2.3 I did the
tweaks I needed and all is ok except request.session_options[:id].
I want to log request.session_options[:id] but I get a nil value,
however after I call the inspect method on request.session ... I no
longer get a nil value for request.session_options[:id].
Example
puts request.session_options[:id] #=> nil
request.session.inspect
puts request.session_options[:id] #=>
'b7a45b2bcc227cc34b2b58603822d91c'
Comments and changes to this ticket
-
Simone Carletti March 17th, 2009 @ 05:09 PM
I get the same error but running functional tests.
I've the following method
def something user_cookie = cookies[:user_cookie] || session.session_id end
changing the method definition to
def something user_cookie = cookies[:user_cookie] || request.session_options[:id] end
causes the following error.
NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] app/controllers/application_controller.rb:38:in `something' test/functional/about_controller_test.rb:16:in `test_index'
-
Pawel March 18th, 2009 @ 03:08 PM
- Tag changed from 2.3, rails, request.session:id, session.session_id to 2.3, rails, request.session_options:id, session.session_id
This is because of session lazy loading.
You can work around this by loading the session first and then read its id.
def something session[:foo] user_cookie = cookies[:user_cookie] || request.session_options[:id] end
However I think there should be a way to read session id without loading the session itself (think of database backed sessions) -- see #2177.
-
edbond2 June 30th, 2009 @ 06:57 AM
- Assigned user set to josh
- Tag changed from 2.3, rails, request.session_options:id, session.session_id to 2.3, cookie, rails, request, session, test
-
josh July 9th, 2009 @ 07:32 PM
- State changed from new to open
I suppose trying to read the session id should touch the cookie store.
Can someone try to create a patch for this?
Also, this should only affect the cookie store. For an example, with the AR store, we don't want to load the session because we already know the session id.
-
josh July 23rd, 2009 @ 03:08 AM
- State changed from open to incomplete
-
josh August 19th, 2009 @ 03:55 PM
- Assigned user cleared.
-
John Pignata August 19th, 2009 @ 05:41 PM
I'm not sure how to retrieve the ID without unmarshaling the cookie data and it seems reasonable to me to load this data if the id is requested so I've created a patch to do that. This should apply to 2-3-stable. Feedback welcomed - not sure what the best way is to fix this.
-
josh August 31st, 2009 @ 10:20 PM
- Milestone cleared.
CookieStore should probably wrap session.options with a lazy hash that triggers the unmarshaling.
-
John Pignata September 2nd, 2009 @ 03:30 AM
Thanks, Josh. Here's another go at it - against master this time.
-
josh September 2nd, 2009 @ 03:39 AM
- Assigned user set to josh
- State changed from incomplete to open
-
Repository September 3rd, 2009 @ 05:50 PM
- State changed from open to resolved
(from [e0f1a7dc191ffebc9f6cadb6232e567fee8aa491]) If session_options[:id] is requested when using CookieStore, unmarshal the session to access it [#2268 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com
http://github.com/rails/rails/commit/e0f1a7dc191ffebc9f6cadb6232e56... -
John Pignata September 3rd, 2009 @ 06:29 PM
Looking at your commit, it seems like I made an error when testing the bugfix. CookieStore should be deriving from Hash. I've made a patch to revert this unnecessary change.
-
Repository September 3rd, 2009 @ 09:15 PM
(from [bd97c3044a7b135f5b84f38c3dbdce2ccc793f70]) CookieStore should not be derived from Hash - reverting [#2268 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com
http://github.com/rails/rails/commit/bd97c3044a7b135f5b84f38c3dbdce... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2268 rails 2.3 session_options[:id] problem (from [e0f1a7dc191ffebc9f6cadb6232e567fee8aa491]) If sess...
- 2268 rails 2.3 session_options[:id] problem (from [bd97c3044a7b135f5b84f38c3dbdce2ccc793f70]) CookieS...