Fail rollback transaction with manual raise exception

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)

save! just throws an error if there is an issue. Do you have
validations that are supposed to cause an exception in that case?

Actually you need to put that in an exception block. You are saving
the data before the raise.

According to the ActiveRecord documentation, any exception thrown
inside a transaction block must rollback all updates have been made
within the transaction.

ActiveRecord::Rollback =>
“Normally, raising an exception will cause the transaction method to
rollback the database transaction and pass on the exception”

Yes I tried ‘raise ActiveRecord::Rollback’ without ‘.new’, but i have
the same problem.

On Jul 23, 4:45 pm, Carlos F. [email protected] wrote:

but the record bank is saved succesfully into database

what does the corresponding log file look like ?

Fred

Did you try ‘raise ActiveRecord::Rollback’ ?

without the .new

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