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 uniqueness constraint when reading from mongoengine.
[<A: A object>, <A: A object>, <B: B object>]
Traceback (most recent call last):
File "unique3.py", line 20, in <module>
print B.objects
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 1131, in __repr__
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 776, in __getitem__
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 427, in _cursor
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 402, in _collection
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 717, in ensure_index
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 639, in create_index
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 270, in insert
File "build/bdist.linux-i686/egg/pymongo/connection.py", line 732, in _send_message
File "build/bdist.linux-i686/egg/pymongo/connection.py", 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()
connection.drop_database('tmp-unique')
db = connection['tmp-unique']
db.a.save({'_cls': 'A', '_types': ['A']})
db.a.save({'_cls': 'A', '_types': ['A']})
db.a.save({'_cls': 'A.B', '_types': ['A', 'A.B'], 'foo': True})
class A(Document):
pass
class B(A):
foo = BooleanField(unique=True)
connect('tmp-unique')
print A.objects
print B.objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment