This can happen if you execute the wrong SQL statement in the transaction scope, you throw an exception from this statement, and then try to execute another SQL statement in the same transaction.
Once one statement in a transaction fails, no more statements can be executed in this transaction.
Here is an example:
ActiveRecord::Base.transaction do begin ActiveRecord::Base.connection.execute "A bad query" rescue => ex puts ex.message end puts User.count end
User.count calls PG::InFailedSqlTransaction because the previous SQL statement raised ActiveRecord::StatementInvalid and was swallowed by rescue .
So, I would look for code that saves as part of a transaction, and then try to run additional SQL statements.
Scott Jacobsen
source share