Skip to content

Instantly share code, notes, and snippets.

@tfausak
Created March 24, 2011 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfausak/885218 to your computer and use it in GitHub Desktop.
Save tfausak/885218 to your computer and use it in GitHub Desktop.
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