Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes deprecation warning: ActiveRecord::Base.raise_in_transactional_callbacks=?

I get this message when I run my feature specs:

DEPRECATION WARNING: ActiveRecord::Base.raise_in_transactional_callbacks= is deprecated, has no effect and will be removed without replacement.

I am using Rails 5.0.0.rc1 and am not sure what is throwing this deprecation warning.

I had this in my application.rb file. I removed it and the deprecation warning went away:

config.active_record.raise_in_transactional_callbacks = true

I'd like tips on what this deprecation warning actually means and to know what triggers this deprecation warning.

like image 231
Neil Avatar asked May 26 '16 15:05

Neil


2 Answers

I believe this behaviour was added between 4.1 and 4.2 as a temporary solution to a problem which is no longer relevant in rails 5:

http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#error-handling-in-transaction-callbacks

Currently, Active Record suppresses errors raised within after_rollback or after_commit callbacks and only prints them to the logs. In the next version, these errors will no longer be suppressed. Instead, the errors will propagate normally just like in other Active Record callbacks.

When you define an after_rollback or after_commit callback, you will receive a deprecation warning about this upcoming change. When you are ready, you can opt into the new behavior and remove the deprecation warning by adding following configuration to your config/application.rb:

config.active_record.raise_in_transactional_callbacks = true

For clarification, as @pixelearth suggests my comment below isn't clear/prominent enough. In Rails 5 and later remove the line from config/application.rb:

config.active_record.raise_in_transactional_callbacks = true

like image 81
R. Hatherall Avatar answered Oct 18 '22 12:10

R. Hatherall


Writing this here for more visbility for @R. Hatherall's comment.

I was getting this warning when upgrading to 5 not becuase I DIDN't have the following setting in application.rb, but because I DID.

In rails 5 remove the following line from application.rb

config.active_record.raise_in_transactional_callbacks = true
like image 38
pixelearth Avatar answered Oct 18 '22 13:10

pixelearth