rubyist / aasm
- Source
- Commits
- Network (92)
- Issues (10)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
-
State transitions do not persist to DB in ActiveRecord models
3 comments Created 8 months ago by Jarylfoo.bar! does not persist to the database due to a failed validation. The documentation for the WriteState::aasm_write_state method indicates that update_attribute is being used to bypass validation, but this is not the case.
After calling write_attribute, save is being called to persist the changes. Since save does validation, this breaks the design of state transitions in AASM.
A proposed fix would be to call save(false) to skip validation, see pastie:
Comments
-
State transitions fire and return true but do nothing
2 comments Created 6 months ago by jamesarosenI have a class:
class Item < ActiveRecord::Base include AASM aasm_initial_state :available aasm_state :available aasm_state :in_use aasm_event(:check_out) do transitions :from => :available, :to => :in_use end aasm_event(:check_in) do transitions :from => :in_use, :to => :available end endThis works:
i = Item.create! i.write_attribute(:state, 'in_use') # => "in_use" i.save! # => true i.state # => "in_use"But this doesn't do anything:
i = Item.create! i.check_out! # => true i.state # => "available"Comments
jamesarosen
Mon Jun 22 07:01:49 -0700 2009
| link
This is running on version 2.0.5:
gem list rubyist *** LOCAL GEMS *** rubyist-aasm (2.0.5)This is the same problem as issue #2, see here: http://github.com/rubyist/aasm/issues/#issue/2
-
Hi, the problem i've described in subj. Possible - it may be solution - http://github.com/railsbob/aasm/commit/faa145834614bd9d4a02f8c114fc736d26e1323e
Comments
-
I need an 'after' call back just like acts_as_state_machine. It is posable that a callback may need to transition to a new state, currently that isn't posable since the state transition hasn't completed yet when the 'enter' callback is called. This might happen for example when you call a pay! action, and may end up with a 'cleared' or 'decline' state.
Comments
-
aasm_column :state aasm_initial_state :pending
aasm_state :pending aasm_state :current, :enter => :deliver aasm_state :old, :enter => :end_nowaasm_event :activate do
transitions :from => :pending, :to => :currentend
aasm_event :expire do
transitions :from => :current, :to => :oldend
-------------- RSpec:
it "should transition from pending to current with activate! event" do
@my_obj.activate! @my_obj.state.should eql('current')end
it "should transition from current to old with expire! event" do
@my_obj.activate! @my_obj.state.should eql('current') @my_obj.expire! @my_obj.state.should eql('old')end
Although the expire even calls the callback 'end_now', it never transitions the model to the 'old' state. While on the contrary activate! does transition the state correctly. Removing the callback from 'old' doesn't help. I can't see any reason this would fail.
Comments
I'm trying to reproduce the failure, but I'm unable to with the latest version (2.0.7). The spec I'm using is http://gist.github.com/164453 Can you make this fail so I can get a better idea of what the problem is?
-
Hello,
I don't actually know that much about AASM, but it's part of a project I'm involved in that I wanted to graph using railroad. Unfortunately, railroad crashes when it processes AASM - but it appears to be due to a bug in AASM. There seem to be lots of people wanting to do something similar. I believe I've identified the problem, and a solution that at least fixes the railroad crash, so I thought I would let you know.
When railroad runs against projects that use AASM, it crashes with a stack overflow. I don't really understand the AASM code, so I can't really tell if this could happen under normal operations. I've identified the "bug" and a "fix." The fix seems safe, but it's definitely a band-aid. If the problem can't come up in normal operation, then the band-aid is probably sufficient.
The problem occurs on line 242 of active_record_persistence.rb (as for versions, I don't use git, but FWIW, the file I downloaded is called rubyist-aasm-7a1c70158c67113bc1c8dd6bd6dbd327af150648):
module NamedScopeMethods def aasm_state_with_named_scope name, options = {}aasm_state_without_named_scope name, options self.named_scope name, :conditions => { "#{table_name}.#{self.aasm_column}" => name.to_s} unless self.respond_to?(name) end endThe problem seems to be that for some reason, when railroad tries to process AASM code, the aliasing earlier in this file causes the above method to call itself:
(lines 44-50)
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 endThe band-aid fix is to put a limiter on the call like so:
aasm_state_without_named_scope name, options.merge(:called_as_unnamed => true) unless options[:called_as_unnamed]I believe this is safe because it seems to me that in any case, if this line is calling the function that contains it, then it's going to crash anyway.
-Avram
Comments
-
Hi,
I have an app that uses a form-wizard that allows you to go forwards/backawards to form pages. The logic to keep up with the current page is a bit clunky and it sounds like aasm might be a good improvement. I would use a form page as a 'state', then use aasm to track what the next/previous pages are.
However, admin users can create form pages dynamically and these get stored in the database via ActiveRecord. How would you deal with this in aasm, where states are typically static?
Kim
Comments
-
Is it intentional that the :enter method is not called for the initial state?
(i.e. if this is intentional, let me know and I'll update the README)e.g. with the following AASM definition, the do_create is not called on the initial creation of the object.
include AASM aasm_column :state aasm_initial_state :pending aasm_state :pending, :enter => :do_create aasm_state :active, :enter => :do_activate aasm_event :activate do transitions :to => :active, :from => [:pending] end aasm_event :deactivate do transitions :to => :pending, :from => [ :active ] endComments
:enter is called, however the question is "when is the initial state entered?"
Since you can't enter the state on initialize (objects are often not fully populated yet) aasm waits till aasm_enter_initial_state is called (from the first call aasm_current_state or save)Problem is that it is not a full event so the persistence sequence is a little messed up the way the code is currently. If you execute a state transition in :enter or :after_enter it will execute in the middle of the first save but the new state won't stick. It seems to persist the :initial_state.
-
on_transition method call requires extra parameter
2 comments Created 2 months ago by twalpoleWhen using the :on_transition option to transitions argument passing requires an extra parameter
aasm_event :something do
transitions :from=>:state1, :to=>:state2, :on_transition=>:foo
end
def foo(a,b)
...... endIn this case for foo to be called with a=1 and b=2 when the transition occurs we need to call
something(nil,1,2) or something(:state2,1,2) - This is because the first parameter is taken as the destination state. This seems superfluous when there is only one destination state - Could this be changed to support a syntax like something(1,2) in the case of only one destination state or something(1,2,:to=>:state2) in the case of multiple possible destinations?Comments
jbarreneche
Thu Oct 15 13:51:58 -0700 2009
| link
I'm not familiar with the project, but I was thinking the same thing!! I don't like the extra parameter!
But, I think the syntax you are proposing it's not likely to be implemented because, how would someone know if the last hash it's the target state or is just another parameter for the transition method?
I was thinking this syntax:
Keep it as a first parameter but, if the first parameter received by the event It's a symbol then it's taken as the target state and not passed to the method. If not, all the parameters are passed to the method.ie:
obj.something 1,2 #=> foo 1,2 obj.something :state, 1, 2 #=> foo 1,2 obj.something nil, 1, 2 #=> foo 1, 2 (I'm not sure if I like this last one)WDYT?
I will fork the project and give it a try to make a patch for thisAnother option could be to add the method
something_default 1,2 #=> foo 1,2 something nil, 1,2 #=> foo 1,2 something :state2, 1,2 #=> foo 1,2or (if the first it's ugly) add the suffix "_to_state" when you want to select the target state
something_to_state :state2, 1, 2 #=> foo 1, 2 something_to_state nil, 1, 2 #=> foo 1, 2 something 1, 2 #=> foo 1, 2PS: I hope it's clear what I wrote =P... My english it's very poor... Un_n...
jbarreneche
Thu Oct 15 14:19:46 -0700 2009
| link
Here's the commit to make this work:
obj.something 1,2 #=> foo 1,2 obj.something :state, 1, 2 #=> foo 1,2http://github.com/jbarreneche/aasm/commit/ef1d080d972a17cd31bfa905952f5d0dc61289b4
-
The callback chain description should be corrected
0 comments Created 2 months ago by unigatePlease, change in README.rdoc
oldstate:after_enter
to
newstate:after_enterComments






just got bitten by this bug myself.
Yeah, and you'd think that more people would be experiencing this. There are 556 watchers.
I forked the repo and fixed the error @ http://github.com/Jaryl/aasm/tree/master. Now, how does this thing work, should I leave it at this or do I submit a pull request or what?