The upgrade I'm working on is
- Ruby 2.6
- MongoDB 3.6
- Mongoid from 5.0 to 7.1
- Rails from 4.2 to 5.2
I have a call back that halts future callbacks under a condition. Now that I have to use throw(:abort) to halt callbacks and prevent a save operation Mongoid will then throw:
Mongoid::Errors::Callback:
message:
Calling save! on Survey resulted in a false return from a callback.
summary:
If a before callback returns false when using Document.create!, Document#save!, or Document#update_attributes! this error will get raised since the document did not actually get saved.
resolution:
Double check all before callbacks to make sure they are not unintentionally returning false.
This is problematic. We're not even expecting an error message, that is logged and we move on. We just want record.save to return false. How do I suppress this exception from Mongoid?
The problem is that I was throwing as well as returning false. Just throw(:abort).