Remove transaction around Spree::Payment state transitions.#4603
Remove transaction around Spree::Payment state transitions.#4603shioyama wants to merge 1 commit intospree:1-3-stablefrom
Conversation
Wrapping state transitions around payment processing in a transaction means that if an after callback (say a failure in a shipment) will actually rollback the payment, even if it was successful. Removing it still leaves the action itself (ActiveRecord save) within a transaction.
|
Thanks @shioyama, could you add a regression spec for this as well please? 👍 |
|
@peterberkenbosch thanks will do. |
I'm not so sure about that @shioyama guess we need to review it more carefully. Take the On the use case you described above, couldn't you take care of that failure on your method, like rescue the exception for example, so that the transaction is not rolled back? Assuming it should not really stop the state flow anyway. |
|
@huoxito I suppose in a way I wrote that to be provocative, to get a discussion going on this. 😉 It seems to be a really important aspect of how the spree checkout/payment flow works, but one that hasn't been analyzed carefully enough (IMHO).
If that's a concern, you should look at #4542 and #4499 again, because they strip the transactions around checkout flow state machine callbacks. This affects callbacks for all transitions, including The thing is, though, transactions are a double-edged sword here. As I mentioned in those PRs, transactions on the order state machine also wrap payment transitions, so the payment In the case here, payment callbacks, I think the case can be made that the transaction is a bad thing. If a payment is successful, and something fails in a callback, then what do you want the state to be? If you rollback the transaction, the payment becomes What we want in our case is for the This particular one we can solve with an |
|
I'm still ok with dropping the transactions on order state machine. Just And here I cant see an issue really because users can work around the Washington L Braga Jr
|
|
@huoxito Fair enough, I'll just save in an after rollback callback or something, and close this for now. Thanks. |
Similar to #4542 and #4499.
Payment state transitions are wrapped in transactions. In the case we are working with, we have a payment observer that runs an
after_transitioncallback which triggers an electronic shipment, which can occasionally fail. When it fails it rolls back the entire transaction, including the payment.This means that although the payment has been successfully processed, we see it as pending.
Stripping the transaction does not seem to cause any problems, and allows for this type of case (i.e. where a payment has succeeded, but an
after_callbackhas failed) to persist the payment to the db.I'm submitting this to
1-3-stablesince that's what we're working with, but it should apply to master as well. I can add a test too, just let me know.I think in general that no state transitions on spree models really need to be wrapped in transactions, they are just set that way by default by
state_machine.