Skip to content

Instantly share code, notes, and snippets.

Created Mar 24, 2011
What would you like to do?
Minimal example that causes a uniqueness constraint when reading from mongoengine.
[<A: A object>, <A: A object>, <B: B object>]
Traceback (most recent call last):
File "", line 20, in <module>
print B.objects
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/", line 1131, in __repr__
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/", line 776, in __getitem__
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/", line 427, in _cursor
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/", line 402, in _collection
File "build/bdist.linux-i686/egg/pymongo/", line 717, in ensure_index
File "build/bdist.linux-i686/egg/pymongo/", line 639, in create_index
File "build/bdist.linux-i686/egg/pymongo/", line 270, in insert
File "build/bdist.linux-i686/egg/pymongo/", line 732, in _send_message
File "build/bdist.linux-i686/egg/pymongo/", line 684, in __check_response_to_last_error
pymongo.errors.OperationFailure: E11000 duplicate key errorindex: tmp-unique.a.$foo_1 dup key: { : null }
from mongoengine import *
from pymongo import Connection
connection = Connection()
db = connection['tmp-unique']{'_cls': 'A', '_types': ['A']}){'_cls': 'A', '_types': ['A']}){'_cls': 'A.B', '_types': ['A', 'A.B'], 'foo': True})
class A(Document):
class B(A):
foo = BooleanField(unique=True)
print A.objects
print B.objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment