Rake aborted! stack level too deep


#1

Hello,

I have trouble with migration files. Every time when I try create a
record by migration file I have error: “Rake aborted! stack level too
deep”
(look bellow to see content of my migration file and my rails
environment)

This error is very tricky, I do hot sure but sounds like this error
happen
when ruby could not find a method

I found that problem at the two places. One is:
‘paginating find’ plugin
http://cardboardrocket.com/pages/paginating_find

and second is:
‘userstamp’ plugin
http://www.delynnberry.com/articles/category/userstamp/

There is code at the paginating find:

def self.included(base)
base.extend(ClassMethods)
base.class_eval do
class << self
alias_method_chain :find, :pagination
end
end
end

def find_with_pagination(args)
options = extract_options_from_args!(args)



# The :page option was not specified, so invoke the
# usual AR::Base#find method
find_without_pagination(
(args << options))
end
end

I can see at the log that error happen after when was executed
-> body of find_with_pagination
-> call find_without_pagination(*(args << options))
-> body of find_with_pagination
-> options = extract_options_from_args!(args)

As I can understand the ‘find_without_pagination’ method call
executes ‘find_with_pagination’ instead.

Sounds like alias_method_chain :find, :pagination does not work with
rake
(that is strange, should not be like that).

I fixed the trouble but solution was not great. I have replaced:
alias_method_chain :find, :pagination

By:
alias_method :pagination_find, :find_with_pagination
alias_method :find_without_pagination, :find

And all places where I need a pagination find I use ‘pagination_find
method’
and use just ‘find’ at other cases

Other place which makes error is a userstamp plugin
And here the same trouble

alias_method :create_without_user, :create
alias_method :create, :create_with_user
alias_method :update_without_user, :update
alias_method :update, :update_with_user

def create_with_user
if record_userstamps and user_model.current_user != nil
write_attribute(:created_by, user_model.current_user.id.to_i) if
respond_to?(:created_by) and self.created_by.nil?
write_attribute(:updated_by, user_model.current_user.id.to_i) if
respond_to?(:updated_by)
end
create_without_user
end

class Base
@@user_model_name = :users
cattr_accessor :user_model_name

@@record_userstamps = true
cattr_accessor :record_userstamps

def self.relates_to_user_in(model)
  self.user_model_name = model
end

def user_model
  Object.const_get(self.user_model_name.to_s.singularize.humanize)
end

end

When user_model is
Object.const_get(self.user_model_name.to_s.singularize.humanize)
It has error at the singularize (look at reports bellow)

When I changed code of user_model to just return User the error at the
method create_with_user when it try call create_without_user

Sounds like it can’t find create_without_user method. At result there
is same trouble with alias_method and migration as abowe

And last point. The troubles only with rake and no troubles
when application works as web server.

My migration file

class CreateDefUsers < ActiveRecord::Migration
  def self.up
    User.create( { :id => 1,
      :login => 'root', :password => "root",
:password_confirmation=>"root",
      :email=>"removed_email_address@domain.invalid", :role =>:root, :company_id=>1 } )

  end
  def self.down
  end
end

Error message when:

def user_model
User
end

== CreateDefUsers: migrating

rake aborted!
stack level too deep
D:/AppFrameWork/RAdmin/config/…/vendor/plugins/userstamp/lib/userstamp.rb:32:in
create_without_user' D:/AppFrameWork/RAdmin/config/../vendor/plugins/userstamp/lib/userstamp.rb:36:increate’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1789:in
create_or_update_wit hout_callbacks' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:242:increate_or_update

C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in
save_without_validat ion' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:insave_without_t
ransactions’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in
save' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database _statements.rb:59:intransaction’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in
transaction' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:intransaction’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in
save' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:451:increate’
./db/migrate//014_create_def_users.rb:3:in real_up' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:insend’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in
migrate' C:/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in
migrate' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:335:inmigrate’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in
each' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:inmigrate’
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:297:in
up' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:288:inmigrate’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:4
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in call' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:inexecute’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:inexecute’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in invoke' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:insynchronize’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in invoke' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:intop_level’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in each' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:intop_level’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in
standard_exception_handling' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:intop_level’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in run' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:instandard_exception_handling’
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in run' C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7 C:/ruby/bin/rake.bat:20:inload’
C:/ruby/bin/rake.bat:20

Error message when:

  def user_model
    Object.const_get(self.user_model_name.to_s.singularize.humanize)
  end


== CreateDefUsers: migrating
==================================================
rake aborted!
stack level too deep
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/inflector.rb:120:in
`singularize'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/string/inflections.rb:33:in
 `singularize'
D:/AppFrameWork/RAdmin/config/../vendor/plugins/userstamp/lib/userstamp.rb:65:in
`user_model'
D:/AppFrameWork/RAdmin/config/../vendor/plugins/userstamp/lib/userstamp.rb:32:in
`create_without_user'
D:/AppFrameWork/RAdmin/config/../vendor/plugins/userstamp/lib/userstamp.rb:36:in
`create'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1789:in
`create_or_update_wit
hout_callbacks'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:242:in
`create_or_update
'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in
`save_without_validat
ion'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in
`save_without_t
ransactions'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in
`save'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database
_statements.rb:59:in `transaction'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in
`transaction'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in
`transaction'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in
`save'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:451:in
`create'
./db/migrate//014_create_def_users.rb:3:in `real_up'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in
`send'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in
`migrate'
C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:212:in
`migrate'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:335:in
`migrate'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in
`each'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in
`migrate'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:297:in
`up'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:288:in
`migrate'
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:4
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in
`synchronize'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in
`top_level'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in
`top_level'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in
`standard_exception_handling'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in
`top_level'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in
`standard_exception_handling'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7
C:/ruby/bin/rake.bat:20:in `load'
C:/ruby/bin/rake.bat:20

My Rails Enviroment

Windows XP SP2
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
rails-1.2.3


#2

Hmmm, my message was not clear… I want give few important comments

Other place which makes error is a userstamp plugin
And here the same trouble

Next going the code of userstamp plugin

alias_method :create_without_user, :create
alias_method :create, :create_with_user
alias_method :update_without_user, :update
alias_method :update, :update_with_user

Other thing

Error message when:
def user_model
User
end

I mean that the user stamp has the method ‘user_model’ which is actualy
different and make error also (what is also I need to understand), but I
replace that code to this simple variant:

Also when error log has next lines at the top of log:

rake aborted! stack level too deep
D:/AppFrameWork/RAdmin/config/…/vendor/plugins/userstamp/lib/userstamp.rb:32:in
`create_without_user’
D:/AppFrameWork/RAdmin/config/…/vendor/plugins/userstamp/lib/userstamp.rb:36:in

The source code had linenumbers

31 def create_with_user
32 if record_userstamps and user_model.current_user != nil
33 write_attribute(:created_by, user_model.current_user.id.to_i)
if respond_to?(:created_by) and self.created_by.nil?
34 write_attribute(:updated_by, user_model.current_user.id.to_i)
if respond_to?(:updated_by)
35 end
36 create_without_user
37 end

Function call order is:
-> create_with_user
-> create_without_user
-> create_with_user

So stack overflowed cause the function calls byself.


#3

I found similar trouble here
http://wrath.rubyonrails.org/pipermail/rails/2006-February/015273.html


#4

Valeriya Alex wrote:

I found similar trouble here
http://wrath.rubyonrails.org/pipermail/rails/2006-February/015273.html

As result, I have recoded plug-ins source with inheritance. And I will
avoid of using class extending with ‘alias_method’