This project is archived and is in readonly mode.
rails 2.3 session_options[:id] problem
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].
puts request.session_options[:id] #=> nil
puts request.session_options[:id] #=> 'b7a45b2bcc227cc34b2b58603822d91c'
Comments and changes to this ticket
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'
- 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.
- 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.
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.
- State changed from open to resolved
Signed-off-by: Joshua Peek email@example.com
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Tickets have moved to Github
The new ticket tracker is available at https://github.com/rails/rails/issues