Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I fix Stack Overflow after upgrading rails 2.0.2 to 2.3.5 (or even 2.1.0) => in ActiveRecord::SessionStore
    text
    copied!<p>Ok, so we're upgrading a client's legacy code from 2.0.2 to latest rails. Most of the basics were easy to fix, but I can't get to the admin screens. Every time we hit "current_user" we get a "stack level too deep" error.</p> <p>I've dug deeply into the code (read: flailed around a lot at random) and I've finally narrowed it down to the ActiveRecord::Session store.</p> <p>The code berks out on the line that includes "session[:user]".</p> <p>When I spool up script/console I can replicate the stack overflow with the following line:</p> <pre><code>s = ActiveRecord::SessionStore::Session.new(:session_id =&gt; '42', :data =&gt; {}) </code></pre> <p>stacktrace to follow.</p> <p>To make sure it wasn't some weird incompatibility, I blew away the session table in the db and reloaded using rake db:sessions:create and it's still asploding on that line.</p> <pre><code>SystemStackError: stack level too deep from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/schema_definitions.rb:68:in `type_cast' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:161:in `field_changed?' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:132:in `write_attribute_without_dirty' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:139:in `write_attribute' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:211:in `session_id=' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2746:in `send' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2746:in `attributes=' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2742:in `each' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2742:in `attributes=' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2438:in `initialize' from (irb):10:in `new' </code></pre> <p>I went into active_record and put in heaps of puts lines. Here's a brief version the final two lines are continually repeated and are clearly the stack-overflow... but why does column_for_attribute(session_id) cause an overflow?</p> <pre><code>"in respond_to? method: session_id=" "in respond_to? session_id= - there are no generated methods. generating..." "in respond_to? session_id= - methods generated" "responds to session_id=? y" "in respond_to? method: session_id=" "in respond_to? session_id= - super is true" "in read_attribute: session_id about to fetch value" "fetched attr value: nil" "read attr: session_id - value nil" "column for attribute: session_id" "c_for_a got col hash - accessing for name: session_id" "column for attribute: session_id" "c_for_a got col hash - accessing for name: session_id" "column for attribute: session_id" "c_for_a got col hash - accessing for name: session_id" "column for attribute: session_id" "c_for_a got col hash - accessing for name: session_id" </code></pre> <p>Note: we also tried upgrading just to 2.1.0 and the same error occurs (when trying to login - obviously the session-class changed names in between so the scipt/console issue depends on the classname). This time it's endlessly trying just "id" instead of "session_id".</p> <p>Current environment.rb session settings (for the 2.1.0 version) is below:</p> <pre><code># Use the database for sessions instead of the file system # (create the session table with 'rake db:sessions:create') config.action_controller.session_store = :active_record_store config.action_controller.session = { :session_key =&gt; "_our_session_id", :secret=&gt; "some random secret key of your choosing over 30 characters" } </code></pre> <p>If I drop it back to v2.0.2 it works again.</p> <p>So I guess the question is: what changed in the ActiveRecord Session between v 2.0.2 and 2.1.0 and how do I make it work?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload