Sinatra project with activerecord gem raise a warning:
DEPRECATION WARNING: Currently, Active Record suppresses errors raised
within `after_rollback`/`after_commit` callbacks and only print 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.
You can opt into the new behavior and remove this warning by setting:
**config.active_record.raise_in_transactional_callbacks = true**
Gemfile.lock
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
How to remove this? thanks!
EDIT: The mini project is here https://gist.github.com/williamhqs/c127e5d7018aa61cb02a
The error message tells you what to do. In Rails, add this line to your application for the time being:
config.active_record.raise_in_transactional_callbacks = true
In Sinatra, you can do it directly on ActiveRecord::Base
:
ActiveRecord::Base.raise_in_transactional_callbacks = true
Keep in mind that this configuration option itself will be deprecated with the next release of Active Record.
Patrick is right, to remove the warning and go to the new behaviour, you should add
Rails : config.active_record.raise_in_transactional_callbacks = true
Sinatra : ActiveRecord::Base.raise_in_transactional_callbacks = true
I think a little background on what it exactly does is important : https://github.com/rails/rails/pull/16537 and https://github.com/rails/rails/pull/14488
Actual Behaviour for after_commit / after_rollback : When there is an error, the error is logged however it's not shallowed. Meaning that the error does not stop the current execution.
Futur Behaviour for after_commit / after_rollback : When there is an error, the error is logged and WILL NOT BE shallowed. Meaning that the error WILL STOP the current execution.
The warning displayed is only here to inform you of that futur behaviour, and this warning will be removed on futur versions of Rails / ActiveRecord.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With