hmarr/mongoengine — Issue #391: Duplicate key on delete
Author: Uznick
Created: 2011-12-11 13:56:45+00:00
State: open

I have simple model called Items.

When I do

items = get_document_or_404(Items, pk=cat_id)
items.delete(safe=True)

I get OperationError exception: Could not delete document (E11000 duplicate key error index: project.items.$_id_ dup key: { : ObjectId('4ee4b37f2b6774cb32000006') })

Why does it raise duplicate key exception on delete and how to fix that? While debugging, I got to the request string, that's generated by mongoengine, and that's ok: {'_types': 'Items', '_id': ObjectId('4ee4b25f2b6774ca6e000006')}.

When I send that request to the mongo console -- it deletes the object without any errors.