Wednesday, September 30, 2009

Migrations Containing Loops Cause "stack level too deep" Error If Using acts_as_paranoid in Rails 2.3+

We had trouble today with "stack level too deep" in a Rails application with a migration:

$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  NameOfMigration: migrating ===========================
rake aborted!
An error has occurred, all later migrations canceled:

stack level too deep
/path/to/rails/app/vendor/plugins/acts_as_paranoid/init.rb:3:in `belongs_to_without_deleted'
/path/to/rails/app/vendor/plugins/acts_as_paranoid/init.rb:4:in `belongs_to_without_deleted'
/path/to/rails/app/vendor/plugins/acts_as_paranoid/init.rb:4:in `belongs_to'
The migration involved a loop to copy data from one column to a temporary column as part of the removal of a :default from the column, and the specific code causing the issue was:
  def self.up
    NameOfModel.find(:all).each do |b|

Richard said that we should be using is_paranoid instead of acts_as_paranoid in Rails 2.3+.

After switching to using is_paranoid (which additionally involved removing acts_as_paranoid in our models, and removing acts_as_paranoid under vendor/plugins), this error went away. Thanks, Richard!

No comments: