-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: None
-
Component/s: None
-
None
With the introduction of the after_commit callback in Mongoid 8 I've experienced some bugs that have been very difficult to track down. They stem from the interface discrepancy between Mongoid and ActiveRecord, notably the missing :on option for after_commit. I saw a few issues here related to the question, but I wasn't able to understand why they were closed.
I would argue to add the :on option for two reasons:
1) It would be great to have more granular control of when the callback should be run
2) It will remove the interface discrepancy with ActiveRecord
In my opinion, it's reasonable to assume the interface to be the same as ActiveRecord. Leaving it just slightly different risks breaking things in subtle ways. My app broke due to the use of after_commit in the (popular) third-party gem dragonfly. The missing :on option in this case caused the rest of the code to not be executed leading to some very strange behaviour.