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

    XMLWordPrintable

    Details

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

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: