With : PostgreSQL 8.4 or postgresql-8.3 rails 2.3.4 pg 9.x or pg 8.x I test this code: ========================class NkiBatch < ActiveRecord::Base Bank.connection.transaction do bank = Bank.new(:name => "ddsjdsjdsjk") bank.save! raise ActiveRecord::Rollback.new end end and this: ========================class NkiBatch < ActiveRecord::Base Bank.connection.transaction do bank = Bank.new(:name => "ddsjdsjdsjk") bank.save! raise Exception.new end end and this: ========================class NkiBatch < ActiveRecord::Base Bank.connection.transaction do bank = Bank.new(:name => "ddsjdsjdsjk") bank.save! raise "Please, rollback" end end but the record bank is saved succesfully into database (I reported the problem in the community of pg driver, but they demonstrated that the problem is not the pg driver http://bitbucket.org/ged/ruby-pg/issue/37/fail-rollback-transaction-with-manual-raise) -- 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.
save! just throws an error if there is an issue. Do you have validations that are supposed to cause an exception in that case? On Jul 23, 10:45 am, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> With : > PostgreSQL 8.4 or postgresql-8.3 > rails 2.3.4 > pg 9.x or pg 8.x > > I test this code: > ========================> class NkiBatch < ActiveRecord::Base > Bank.connection.transaction do > > bank = Bank.new(:name => "ddsjdsjdsjk") > bank.save! > raise ActiveRecord::Rollback.new > end > end > > and this: > ========================> class NkiBatch < ActiveRecord::Base > Bank.connection.transaction do > > bank = Bank.new(:name => "ddsjdsjdsjk") > bank.save! > raise Exception.new > end > end > > and this: > ========================> class NkiBatch < ActiveRecord::Base > Bank.connection.transaction do > > bank = Bank.new(:name => "ddsjdsjdsjk") > bank.save! > raise "Please, rollback" > end > end > > but the record bank is saved succesfully into database > > (I reported the problem in the community of pg driver, but they > demonstrated that the problem is not the pg driverhttp://bitbucket.org/ged/ruby-pg/issue/37/fail-rollback-transaction-w...)-- 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.
Actually you need to put that in an exception block. You are saving the data before the raise. On Jul 23, 10:45 am, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> With : > PostgreSQL 8.4 or postgresql-8.3 > rails 2.3.4 > pg 9.x or pg 8.x > > I test this code: > ========================> class NkiBatch < ActiveRecord::Base > Bank.connection.transaction do > > bank = Bank.new(:name => "ddsjdsjdsjk") > bank.save! > raise ActiveRecord::Rollback.new > end > end > > and this: > ========================> class NkiBatch < ActiveRecord::Base > Bank.connection.transaction do > > bank = Bank.new(:name => "ddsjdsjdsjk") > bank.save! > raise Exception.new > end > end > > and this: > ========================> class NkiBatch < ActiveRecord::Base > Bank.connection.transaction do > > bank = Bank.new(:name => "ddsjdsjdsjk") > bank.save! > raise "Please, rollback" > end > end > > but the record bank is saved succesfully into database > > (I reported the problem in the community of pg driver, but they > demonstrated that the problem is not the pg driverhttp://bitbucket.org/ged/ruby-pg/issue/37/fail-rollback-transaction-w...)-- 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.
Carlos Forero
2010-Jul-23 18:38 UTC
Re: fail rollback transaction with manual raise exception
According to the ActiveRecord documentation, any exception thrown inside a transaction block must rollback all updates have been made within the transaction. http://api.rubyonrails.org/classes/ActiveRecord/Rollback.html => "Normally, raising an exception will cause the transaction method to rollback the database transaction and pass on the exception" On Jul 23, 1:06 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> save! just throws an error if there is an issue. Do you have > validations that are supposed to cause an exception in that case? > > On Jul 23, 10:45 am, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > With : > > PostgreSQL 8.4 or postgresql-8.3 > > rails 2.3.4 > > pg 9.x or pg 8.x > > > I test this code: > > ========================> > class NkiBatch < ActiveRecord::Base > > Bank.connection.transaction do > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > bank.save! > > raise ActiveRecord::Rollback.new > > end > > end > > > and this: > > ========================> > class NkiBatch < ActiveRecord::Base > > Bank.connection.transaction do > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > bank.save! > > raise Exception.new > > end > > end > > > and this: > > ========================> > class NkiBatch < ActiveRecord::Base > > Bank.connection.transaction do > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > bank.save! > > raise "Please, rollback" > > end > > end > > > but the record bank is saved succesfully into database > > > (I reported the problem in the community of pg driver, but they > > demonstrated that the problem is not the pg driverhttp://bitbucket.org/ged/ruby-pg/issue/37/fail-rollback-transaction-w...)-- 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.
Did you try ''raise ActiveRecord::Rollback'' ? without the .new On Jul 23, 1:38 pm, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> According to the ActiveRecord documentation, any exception thrown > inside a transaction block must rollback all updates have been made > within the transaction. > > http://api.rubyonrails.org/classes/ActiveRecord/Rollback.html=> > "Normally, raising an exception will cause the transaction method to > rollback the database transaction and pass on the exception" > > On Jul 23, 1:06 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > save! just throws an error if there is an issue. Do you have > > validations that are supposed to cause an exception in that case? > > > On Jul 23, 10:45 am, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > With : > > > PostgreSQL 8.4 or postgresql-8.3 > > > rails 2.3.4 > > > pg 9.x or pg 8.x > > > > I test this code: > > > ========================> > > class NkiBatch < ActiveRecord::Base > > > Bank.connection.transaction do > > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > > bank.save! > > > raise ActiveRecord::Rollback.new > > > end > > > end > > > > and this: > > > ========================> > > class NkiBatch < ActiveRecord::Base > > > Bank.connection.transaction do > > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > > bank.save! > > > raise Exception.new > > > end > > > end > > > > and this: > > > ========================> > > class NkiBatch < ActiveRecord::Base > > > Bank.connection.transaction do > > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > > bank.save! > > > raise "Please, rollback" > > > end > > > end > > > > but the record bank is saved succesfully into database > > > > (I reported the problem in the community of pg driver, but they > > > demonstrated that the problem is not the pg driverhttp://bitbucket.org/ged/ruby-pg/issue/37/fail-rollback-transaction-w...)-- 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.
Carlos Forero
2010-Jul-23 21:21 UTC
Re: fail rollback transaction with manual raise exception
Yes I tried ''raise ActiveRecord::Rollback'' without ''.new'', but i have the same problem. On Jul 23, 3:37 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Did you try ''raise ActiveRecord::Rollback'' ? > > without the .new > > On Jul 23, 1:38 pm, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > According to the ActiveRecord documentation, any exception thrown > > inside a transaction block must rollback all updates have been made > > within the transaction. > > >http://api.rubyonrails.org/classes/ActiveRecord/Rollback.html=> > > "Normally, raising an exception will cause the transaction method to > > rollback the database transaction and pass on the exception" > > > On Jul 23, 1:06 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > save! just throws an error if there is an issue. Do you have > > > validations that are supposed to cause an exception in that case? > > > > On Jul 23, 10:45 am, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > With : > > > > PostgreSQL 8.4 or postgresql-8.3 > > > > rails 2.3.4 > > > > pg 9.x or pg 8.x > > > > > I test this code: > > > > ========================> > > > class NkiBatch < ActiveRecord::Base > > > > Bank.connection.transaction do > > > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > > > bank.save! > > > > raise ActiveRecord::Rollback.new > > > > end > > > > end > > > > > and this: > > > > ========================> > > > class NkiBatch < ActiveRecord::Base > > > > Bank.connection.transaction do > > > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > > > bank.save! > > > > raise Exception.new > > > > end > > > > end > > > > > and this: > > > > ========================> > > > class NkiBatch < ActiveRecord::Base > > > > Bank.connection.transaction do > > > > > bank = Bank.new(:name => "ddsjdsjdsjk") > > > > bank.save! > > > > raise "Please, rollback" > > > > end > > > > end > > > > > but the record bank is saved succesfully into database > > > > > (I reported the problem in the community of pg driver, but they > > > > demonstrated that the problem is not the pg driverhttp://bitbucket.org/ged/ruby-pg/issue/37/fail-rollback-transaction-w...)-- 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-Jul-23 21:25 UTC
Re: fail rollback transaction with manual raise exception
On Jul 23, 4:45 pm, Carlos Forero <ecarlosfor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > but the record bank is saved succesfully into database >what does the corresponding log file look like ? 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.
Carlos Forero
2010-Jul-26 19:17 UTC
Re: fail rollback transaction with manual raise exception
I''m sorry. The problem was the following code that another developer had added: class ApplicationController < ActionController::Base prepend_around_filter :action_transaction def action_transaction ActiveRecord::Base.transaction do yield end end end thanks anyway -- 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.