Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5708

after_commit callback missing :on option

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 9.0.0
    • 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.

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            asgerb Asger Behncke Jacobsen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: