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.

Stack level too deep w/ railroad

#10

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.

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

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Courtenay
    Courtenay

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

    May 10th, 2009 @ 08:19 PM

  2. Courtenay
    Courtenay

    I don't run railroad..

    May 10th, 2009 @ 08:33 PM

  3. Courtenay
    Courtenay

    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
    

    May 10th, 2009 @ 08:46 PM

  4. Dave Nolan
    Dave Nolan
    • 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
      

    May 15th, 2009 @ 10:50 AM

  5. Courtenay
    Courtenay

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

    June 11th, 2009 @ 01:43 PM

  6. Courtenay
    Courtenay

    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.

    June 11th, 2009 @ 11:04 PM

  7. Stuart Piltch
    Stuart Piltch

    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.

    August 10th, 2009 @ 06:20 PM

  8. rubyist
    rubyist

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

    August 25th, 2009 @ 08:32 AM

  9. Stuart Piltch
    Stuart Piltch

    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

    September 3rd, 2009 @ 04:46 PM

  10. Travis Tilley
    Travis Tilley

    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
    

    October 24th, 2009 @ 01:41 AM

  11. Simple Jack
    Simple Jack

    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.

    September 15th, 2020 @ 11:48 PM

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.