Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callbacks endless loop #831

Open
QQDengWangF opened this issue Jun 7, 2023 · 2 comments
Open

callbacks endless loop #831

QQDengWangF opened this issue Jun 7, 2023 · 2 comments

Comments

@QQDengWangF
Copy link

I generated a dead loop by calling the executed event event again in the callback after, and found that it was caused by the state not changing. I found that the state did not change from user in the after method_ Pending transformation success manager_ Pending, is the method I used incorrect?

event :approved_to_state do
  transitions from: :treasurer_pending, to: :success_state
  transitions from: :manager_pending, to: :treasurer_pending
  transitions from: :user_pending, to: :manager_pending, after: proc { before_manager_handler }
  transitions from: :it_pending, to: :user_pending
  transitions from: :leader_pending, to: :it_pending
end

 def before_manager_handler
  puts self.state
  puts "Skip manager_pending“
  self.approved_to_state
end

Through printing, it was found that the value of self.state is always user_ pending, so it constantly executes leading to a dead loop

@QQDengWangF
Copy link
Author

The after method will not be executed after changing state. It is recommended to change the approach or correct the source code for this section

@ccartano
Copy link

I think this is because you dont actually save the object until after the after call. In your after call, the object is still in user_pending, then in the after call, you call the event transition, when then sees its in user_pending, then repeats the process. After is keeping the object as is, telling it to do something before saving but after the tranisition happens. Kinda like using a non-bang vs bang in aasm

To provide a solution, I would think these should be their own events;

event :await_manager_approval do
  transitions from: :user_pending, to: :manager_pending
end

event :await_treasurer_approval do
  transitions from: :manager_pending, to: :treasurer_pendng
end

something of the sort, the issue is that youre recalling a singular event that seems to handle many different state changes before saving the object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants