-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Ensure transition to payment processing state happens outside transaction #4542
Conversation
Sorry, there appear to be a bunch of other errors on master with this commit that didn't come up in #4499. Will investigate. |
This test is now failing but it is unclear if it was ever really testing what it claims to be testing. An order with no email is not valid and should not save, so the test should not pass.
Ok fixed, problem was with the test which was not cleaning up properly in the |
@@ -38,7 +38,7 @@ def self.define_state_machine! | |||
# To avoid multiple occurrences of the same transition being defined | |||
# On first definition, state_machines will not be defined | |||
state_machines.clear if respond_to?(:state_machines) | |||
state_machine :state, :initial => :cart do | |||
state_machine :state, :initial => :cart, :use_transactions => false, :action => :save_state do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the use of save_state
here. Why are you calling that method which is just an alias to save?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is an issue with state_machine
. Using save
as the action name triggers methods which run the state callbacks as ActiveRecord callbacks on the model, which means that they are inside the save
transaction. To get around that, you rename save
to save_state
and alias the method itself. It seems to no longer be mentioned in the inline comments on state machine 1.2.0 but it was there in 1.1.2.
Looks good 👍 thanks! I'm ok with marking that spec as pending for now. |
Ah forgot changelog. Will add now. |
Add failing test showing payment processing is set in a transaction. Mark test of subclassed order as pending. This test is now failing but it is unclear if it was ever really testing what it claims to be testing. An order with no email is not valid and should not save, so the test should not pass. Add changelog entry. Fixes spree#4542
The current method for preventing double payment submissions is simply not working, because the payment state is set in a transaction (see discusion in #4499). This PR turns off transactions on the order state machine and in addition aliases
save_state
tosave
to make this work (see these inline notes for more details on why this is necessary).