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

Mongoid::Paranoia has unintended side-effects on document lifecycle

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      When a paranoid document with a composite unique key (managed by MongoDB) is deleted and then an attempt is made to create a document with the same composite key-voilating the uniqueness constraint in MongoDB-ExampleModel.create! would succeed but the document won't be persisted. ExampleModel.reload would fail, for example.

      This behavior is undocumented and smells like a bug. The semantics of create! are such that if it doesn't raise an error one should be able to trust the instance that comes back.

      There are two possible behaviors that would be semantically valid:

      1. create! should raise an error that is descriptive-enough for a developer to understand that the issue has to do with a live paranoid document.

      2. Mongoid::Paranoia should offer the option to allow new documents to be created that would override existing documents. In other words, it would detect a uniqueness constraint violation and automatically call delete! (or destroy!) and then retry the document creation.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ssimeonov ssimeonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: