Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails 2.3 does not obey config.action_controller.session_store

#2001

Rails 2.3 (edge) does not obey config.action_controller.session_store. If you set:

config.action_controller.session_store = :sql_session_store

Rails does not use the session class. Debug output that I placed in:

vendor/rails/actionpack/lib/action_controller/session_management.rb

Claims that it is loading the class, and this code appears to be referenced:

  def session_store=(store)
    if store == :active_record_store
      self.session_store = ActiveRecord::SessionStore
    else
      @@session_store = store.is_a?(Symbol) ?
        Session.const_get(store.to_s.camelize) :
        store
      puts "DEBUG: session_store=#{@@session_store}"  # prints "SqlSessionStore"
    end
  end

However, the session store is NOT actually used.

The only way to get Rails to use the session store is by adding this line to config/environments/development.rb

config.middleware.use SqlSessionStore

(Per a hint from Josh Peek). Note that this does not work either:

# config/initializers/session_store.rb
ActionController::Base.session_store = :sql_session_store

In both cases, the setting appears to be ignored somewhere later in Rails.

A Rails 2.3-compatible version of SqlSessionStore is available here for testing: git://github.com/nateware/sql_session_store.git

Reported by Nate Wiger · February 18th, 2009 @ 12:08 AM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • Milestone cleared.
    • State changed from new to open

    February 18th, 2009 @ 12:10 AM

  2. Repository
    Repository
    • State changed from open to resolved

    (from [9702636a08e50e9fed9bf76ad620a6a0a109009e]) Lazy evaluate ActionController session store middleware class to pickup custom plugin session stores [#2001 Rails 2.3 does not obey config.action_controller.session_store state:resolved] http://github.com/rails/rails/co...

    February 20th, 2009 @ 03:21 AM

  3. Thibaud Guillaume-Gentil
    Thibaud Guillaume-Gentil

    I can't launch script/server anymore in a default rails app with edge

    
    /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:163:in `ensure_session_key': A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb (ArgumentError)
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/session/cookie_store.rb:74:in `initialize'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:72:in `new'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:72:in `build'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:110:in `build'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/activesupport/lib/active_support/inflector.rb:359:in `inject'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:110:in `each'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:110:in `inject'
    	from /Users/Thibaud/Desktop/test2/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb:110:in `build'
    	 ... 12 levels...
    	from /Users/Thibaud/Desktop/test2/vendor/rails/railties/lib/commands/server.rb:84
    	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    	from ./script/server:3
    

    February 20th, 2009 @ 07:39 AM

  4. Eloy Duran
    Eloy Duran

    Same problem as Thibaud overhere.

    I haven't had the time to investigate, no time so had to revert, but at least it seems there wasn't and isn't enough test coverage for this area, because the tests still run fine.

    February 20th, 2009 @ 09:16 AM

  5. Flurin
    Flurin

    We've encountered the same problem here. Josh tried to fix the problem by letting the MiddlewareStack decide wether or not to load the SessionStore based on wether or not it's available.

    It seems however that because of a default SessionStore (CookieStore) it tries to load that but it hasn't any options set yet. (Because the middlewarestack is initialized before any rails initializers are run).

    February 20th, 2009 @ 11:07 AM

  6. josh
    josh
    • State changed from resolved to open

    February 20th, 2009 @ 04:24 PM

  7. Sven Fuchs
    Sven Fuchs
    • State changed from open to resolved

    I've created a new ticket for this and added a patch: #2028 CookieStore does not get passed config settings

    February 20th, 2009 @ 04:25 PM

  8. josh
    josh
    • State changed from resolved to open

    February 20th, 2009 @ 04:27 PM

  9. josh