Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

fail rollback transaction with manual raise exception

#5187

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
   def create_batches
     Bank.connection.transaction do

       bank = Bank.new(:name => "ddsjdsjdsjk")
       bank.save!
       raise ActiveRecord::Rollback.new
     end
   end
end

and this:

class NkiBatch < ActiveRecord::Base
   def create_batches
     Bank.connection.transaction do

       bank = Bank.new(:name => "ddsjdsjdsjk")
       bank.save!
       raise Exception.new
     end
  end
end

and this:

class NkiBatch < ActiveRecord::Base
   def self.create_batches
     Bank.connection.transaction do

       bank = Bank.new(:name => "ddsjdsjdsjk")
       bank.save!
       raise "Please, rollback"
     end
   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...)

Reported by Carlos Forero · July 23rd, 2010 @ 04:51 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. lakshmanan
  2. Carlos Forero
    Carlos Forero

    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

    July 26th, 2010 @ 08:03 PM

  3. Neeraj Singh
    Neeraj Singh
    • State changed from new to invalid
    • Importance changed from to Low

    July 26th, 2010 @ 08:24 PM