This project is archived and is in readonly mode.
rails 2.3 session_options[:id] problem
-
Simone Carletti
I get the same error but running functional tests.
I've the following method
def something user_cookie = cookies[:user_cookie] || session.session_id endchanging the method definition to
def something user_cookie = cookies[:user_cookie] || request.session_options[:id] endcauses 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
- 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] endHowever I think there should be a way to read session id without loading the session itself (think of database backed sessions) -- see #2177 Unneccessary session loading/creation in form_authenticity_token.
-
edbond2
- 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
- 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
- State changed from open to incomplete
-
josh
- Assigned user cleared.
-
John Pignata
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
- Milestone cleared.
CookieStore should probably wrap session.options with a lazy hash that triggers the unmarshaling.
-
John Pignata
Thanks, Josh. Here's another go at it - against master this time.
-
josh
- Assigned user set to josh
- State changed from incomplete to open
-
Repository
- State changed from open to resolved
(from [e0f1a7dc191ffebc9f6cadb6232e567fee8aa491]) If session_options[:id] is requested when using CookieStore, unmarshal the session to access it [#2268 rails 2.3 session_options[:id] problem state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com
http://github.com/rails/rails/commit/e0f1a7dc191ffebc9f6cadb6232e56... -
John Pignata
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
(from [bd97c3044a7b135f5b84f38c3dbdce2ccc793f70]) CookieStore should not be derived from Hash - reverting [#2268 rails 2.3 session_options[:id] problem state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com
http://github.com/rails/rails/commit/bd97c3044a7b135f5b84f38c3dbdce...
