iwarshak-/Ohng2Vv6ZDR7s880joybQ@public.gmane.org
2010-Feb-09 20:14 UTC
Problem with before_* callbacks being wrapped in transaction
I am upgrading a 2.1 Rails app and ran into a problem with the new way that before_* callbacks are being wrapped in a transaction. I have a model that has a before_create callback which charges the customers credit card. If the transaction is successful it returns true, and if not, false so that the record is not saved. In addition, I have a Cclog audit entry that is created regardless if the transaction is successful or not. This way I keep an audit trail. This worked fine and well until somewhere in the 2.2/2.3 version of rails. Now the entire before_create callback is wrapped in a transaction which means that my Cclog object gets rolled back if the transaction is not successful and returns false. So I cannot keep an audit trail of unsuccessful credit card charges. Is there a way to temporarily disable the transactional nature or the callbacks? The only way I can see getting this to work is moving the transaction/Cclog creation logic into a charge!() method, and making sure to call that method from my controller after it is already saved. Any suggestions? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Feb-09 20:33 UTC
Re: Problem with before_* callbacks being wrapped in transac
iwarshak-/Ohng2Vv6ZDR7s880joybQ@public.gmane.org wrote:> I am upgrading a 2.1 Rails app and ran into a problem with the new way > that before_* callbacks are being wrapped in a transaction. > > I have a model that has a before_create callback which charges the > customers credit card. If the transaction is successful it returns > true, and if not, false so that the record is not saved. In addition, > I have a Cclog audit entry that is created regardless if the > transaction is successful or not. This way I keep an audit trail. > > This worked fine and well until somewhere in the 2.2/2.3 version of > rails. Now the entire before_create callback is wrapped in a > transaction which means that my Cclog object gets rolled back if the > transaction is not successful and returns false. So I cannot keep an > audit trail of unsuccessful credit card charges. > > Is there a way to temporarily disable the transactional nature or the > callbacks? The only way I can see getting this to work is moving the > transaction/Cclog creation logic into a charge!() method, and making > sure to call that method from my controller after it is already saved. > > Any suggestions?Perhaps you could use a savepoint. But check the credit card companies'' regulations; I seem to recall that keeping a log of unsuccessful charges is prohibited... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Feb-09 22:14 UTC
Re: Problem with before_* callbacks being wrapped in transaction
On Feb 9, 8:14 pm, "iwars...-/Ohng2Vv6ZDR7s880joybQ@public.gmane.org" <iwars...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am upgrading a 2.1 Rails app and ran into a problem with the new way > that before_* callbacks are being wrapped in a transaction. > > I have a model that has a before_create callback which charges the > customers credit card. If the transaction is successful it returns > true, and if not, false so that the record is not saved. In addition, > I have a Cclog audit entry that is created regardless if the > transaction is successful or not. This way I keep an audit trail. > > This worked fine and well until somewhere in the 2.2/2.3 version of > rails. Now the entire before_create callback is wrapped in a > transaction which means that my Cclog object gets rolled back if the > transaction is not successful and returns false. So I cannot keep an > audit trail of unsuccessful credit card charges. >use save_without_transactions ? Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
iwarshak-/Ohng2Vv6ZDR7s880joybQ@public.gmane.org
2010-Feb-10 22:00 UTC
Re: Problem with before_* callbacks being wrapped in transac
Won''t this savepoint also be rolled back? Also, I am not storing any credit card numbers, cvv, etc. Basically the last 4 digits, decline code, etc. On Feb 9, 2:33 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> iwars...-/Ohng2Vv6ZDR7s880joybQ@public.gmane.org wrote: > > I am upgrading a 2.1 Rails app and ran into a problem with the new way > > that before_* callbacks are being wrapped in a transaction. > > > I have a model that has a before_create callback which charges the > > customers credit card. If the transaction is successful it returns > > true, and if not, false so that the record is not saved. In addition, > > I have a Cclog audit entry that is created regardless if the > > transaction is successful or not. This way I keep an audit trail. > > > This worked fine and well until somewhere in the 2.2/2.3 version of > > rails. Now the entire before_create callback is wrapped in a > > transaction which means that my Cclog object gets rolled back if the > > transaction is not successful and returns false. So I cannot keep an > > audit trail of unsuccessful credit card charges. > > > Is there a way to temporarily disable the transactional nature or the > > callbacks? The only way I can see getting this to work is moving the > > transaction/Cclog creation logic into a charge!() method, and making > > sure to call that method from my controller after it is already saved. > > > Any suggestions? > > Perhaps you could use a savepoint. > > But check the credit card companies'' regulations; I seem to recall that > keeping a log of unsuccessful charges is prohibited... > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Feb-10 22:28 UTC
Re: Problem with before_* callbacks being wrapped in transac
Please quote when replying. iwarshak-/Ohng2Vv6ZDR7s880joybQ@public.gmane.org wrote:> Won''t this savepoint also be rolled back?Why don''t you try it and find out?> > Also, I am not storing any credit card numbers, cvv, etc. Basically > the last 4 digits, decline code, etc.Check your merchant agreement. I''m no expert, but I''m not sure this is allowed. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.