#10 new
Jonathan Soeder

Stack level too deep w/ railroad

Reported by Jonathan Soeder | January 13th, 2009 @ 05:00 PM

Using the railroad diagram generator in rails projects which rely on AASM throws the following error

vendor/plugins/aasm/lib/persistence/active_record_persistence.rb:240:in aasm_state_without_named_scope': stack level too deep (SystemStackError)

all else works perfectly with AASM. Not sure if this is a problem with aasm or railroad.

Comments and changes to this ticket

  • Courtenay

    Courtenay May 10th, 2009 @ 08:19 PM

    I'm seeing this too. Going to try and get a failing testcase.

  • Courtenay

    Courtenay May 10th, 2009 @ 08:33 PM

    I don't run railroad..

  • Courtenay

    Courtenay May 10th, 2009 @ 08:46 PM

    Appears to be an issue with this code [active_record_persistence.rb:238]

    
          module NamedScopeMethods
            def aasm_state_with_named_scope name, options = {}
              aasm_state_without_named_scope name, options
              self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.respond_to?(name)
            end
          end
    

    If I add this, it makes the problem go away. Not entirely sure if it breaks my code, yet.:

    
          module NamedScopeMethods
            def aasm_state_with_named_scope name, options = {}
    +          return send(name, options) if respond_to?(name)
              aasm_state_without_named_scope name, options
              self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.respond_to?(name)
            end
          end
    
  • Dave Nolan

    Dave Nolan May 15th, 2009 @ 10:50 AM

    • Tag set to persistance, railroad, rspec, stack-level

    Not sure blame lies with AASM here.

    It's not just Railroad, it's anytime that ActiveRecordPersistance is being included more than once in the same class.

    For example:

    class Bar < ActiveRecord::Base
    end
    
    describe Bar do
      #
      # setup/teardown table
      #
      
      before(:all) do
        ActiveRecord::Base.connection.instance_eval do
          drop_table(:bars) if table_exists?(:bars)
          create_table(:bars) do |t| 
            t.datetime :aasm_state
          end
        end
      end
      
      after(:all) do
        ActiveRecord::Base.connection.instance_eval { drop_table(:bars) if table_exists?(:bars) }
      end
      
      it "should not raise an error when including AASM more than once" do
        Bar.send(:include, AASM)
        Bar.send(:aasm_state, :alpha)
        lambda { Bar.send(:include, AASM); Bar.send(:aasm_state, :alpha) }.should_not raise_error
      end
    end
    

    This will fail because ActiveRecordPersistence alias_method line 46, 47 become circular on second inclusion.

    Either manually undef_method the aasm_named_scope methods before including AASM in your class,

    or patch active_record_persistance.rb from line 44 like this:

    base.class_eval do

    class << self
    
    • unless defined_method? :aasm_state_without_named_scope
              alias_method :aasm_state_without_named_scope, :aasm_state
              alias_method :aasm_state, :aasm_state_with_named_scope
      
    •        end
          end
        end
      
  • Courtenay

    Courtenay June 11th, 2009 @ 01:43 PM

    This patch works for me, it seems.. except it's method_defined?, not defined_method?

  • Courtenay

    Courtenay June 11th, 2009 @ 11:04 PM

    There's something in newer versions of rails that fucks with AASM. You also have to do something like

    include AASM unless defined?(AASM)
    

    in your models :( otherwise your states get cleared. Empty states. weird.

  • Stuart Piltch

    Stuart Piltch August 10th, 2009 @ 06:20 PM

    It looks like some of the recent "stack level too deep" problems are related to the new facets. With facets 2.6.0, I get this:

    SystemStackError: stack level too deep
        facets (2.6.0) lib/core/facets/kernel/state.rb:4:in `state'
        facets (2.6.0) lib/core/facets/kernel/state.rb:4:in `state'
        /opt/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.1.1/lib/aasm/persistence/active_record_persistence.rb:235:in `send'
        /opt/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.1.1/lib/aasm/persistence/active_record_persistence.rb:235:in `aasm_read_state'
        /opt/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.1.1/lib/aasm/persistence/active_record_persistence.rb:137:in `aasm_current_state'
        /opt/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.1.1/lib/aasm/aasm.rb:49:in `complete?'
    

    When I downgrade to facets 2.5.2, the problem goes away.

  • rubyist

    rubyist August 25th, 2009 @ 08:32 AM

    Howdy - are you guys experiencing this with the latest from my master (7a1c)?

  • Stuart Piltch

    Stuart Piltch September 3rd, 2009 @ 04:46 PM

    are you guys experiencing this with the latest from my master (7a1c)?

    Using the 2.1.1 gem from gems.github.com (not sure how to tell which git commit it's based on):

    • with facets 2.5.2: no error
    • with facets 2.6.0: SystemStackError: stack level too deep (lib/core/facets/kernel/state.rb:4:in state')
    • with facets 2.7.0: no error

    Using "git clone git://github.com/rubyist/aasm.git" (7a1c) into vendor/plugins (and the gem uninstalled):

    • with facets 2.5.2: no error
    • with facets 2.6.0: SystemStackError: stack level too deep (lib/core/facets/kernel/state.rb:4:in state')
    • with facets 2.7.0: no error
  • Travis Tilley

    Travis Tilley October 24th, 2009 @ 01:41 AM

    this should be fixed in master:

      def self.included(base)
        base.extend AASM::Persistence::ActiveRecordPersistence::ClassMethods
        base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
        base.send(:include, AASM::Persistence::ActiveRecordPersistence::ReadState) unless base.method_defined?(:aasm_read_state)
        base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteState) unless base.method_defined?(:aasm_write_state)
        base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
    
        if base.respond_to?(:named_scope)
          base.extend(AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods)
    
          base.class_eval do
            class << self
              unless method_defined?(:aasm_state_without_named_scope)
                alias_method :aasm_state_without_named_scope, :aasm_state
                alias_method :aasm_state, :aasm_state_with_named_scope
              end
            end
          end
        end
    
        base.before_validation_on_create :aasm_ensure_initial_state
      end
    
  • Simple Jack

    Simple Jack September 15th, 2020 @ 11:48 PM

    I'm having the same issue, can someone please resolve this issue. I cannot work on my PC with this error keeps popping out. I have searched online but still haven't found any solution to this SystemStackError. I even asked in forums about this and they don't know the answer either. II'll just play Harry Potter Hogwarts mystery PC while waiting for some answers.

    Let you kids play gacha club on pc or mobile. It is free to download.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.

Pages