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

Destroying model instances with dependent associations in transactions raises OperationFailure due to use of (deprecated) count

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0.rc1
    • Affects Version/s: None
    • Component/s: Persistence
    • None
    • Environment:
      MongoDB 4.2.x
      Mongoid 7.1.1
      Mongo 2.12.1

      Trying to delete or destroy a model with association definitions that include dependent clauses from within a transaction fails with a Mongo::Error::OperationFailure. This seems to boil down to the calling of #blank? on the relation and how #blank? is implemented https://github.com/mongodb/mongoid/blob/master/lib/mongoid/association/many.rb#L24

      Since a $count operation is not allowed from within a transaction, this results in the OperationFailure exception being raised.

      If it is possible to change the implementation to use #exists? instead of #count? here, it would also provide a slight performance boost as the database can return after finding the first match and isn't forced to inspect the entire collection.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            sven.riedel@givve.com Sven Riedel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: