Skip to Content Skip to Search

TransactionRollbackError will be raised when a transaction is rolled back by the database due to a serialization failure or a deadlock.

These exceptions should not be generally rescued in nested transaction blocks, because they have side-effects in the actual enclosing transaction and internal Active Record state. They can be rescued if you are above the root transaction block, though.

In that case, beware of transactional tests, however, because they run test cases in their own umbrella transaction. If you absolutely need to handle these exceptions in tests please consider disabling transactional tests in the affected test class (self.use_transactional_tests = false).

Due to the aforementioned side-effects, this exception should not be raised manually by users.

See the following: