Skip to content

Instantly share code, notes, and snippets.

@tfausak
Created Mar 24, 2011
Embed
What would you like to do?
Minimal example that causes a mysterious uniqueness constraint when inserting into mongoengine.
Traceback (most recent call last):
File "unique.py", line 15, in <module>
B(foo=True).save()
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/document.py", line 85, in save
mongoengine.queryset.OperationError: Tried to save duplicate unique keys (E11000 duplicate key errorindex: tmp-unique.a.$foo_1 dup key: { : null })
from mongoengine import *
class A(Document):
pass
class B(A):
foo = BooleanField(unique=True)
connect('tmp-unique')
A.drop_collection()
B.drop_collection()
A().save()
A().save()
B(foo=True).save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment