Merge pull request #900

This commit is contained in:
Matthew Ellison 2015-05-06 09:37:56 -04:00
commit 8b7599f5d9
4 changed files with 72 additions and 2 deletions

View File

@ -119,7 +119,7 @@ that much better:
* Anton Kolechkin * Anton Kolechkin
* Sergey Nikitin * Sergey Nikitin
* psychogenic * psychogenic
* Stefan Wójcik * Stefan Wójcik (https://github.com/wojcikstefan)
* dimonb * dimonb
* Garry Polley * Garry Polley
* James Slagle * James Slagle
@ -138,7 +138,6 @@ that much better:
* hellysmile * hellysmile
* Jaepil Jeong * Jaepil Jeong
* Daniil Sharou * Daniil Sharou
* Stefan Wójcik
* Pete Campton * Pete Campton
* Martyn Smith * Martyn Smith
* Marcelo Anton * Marcelo Anton

View File

@ -14,6 +14,7 @@ Changes in 0.9.X - DEV
- Fixed unpickled documents replacing the global field's list. #888 - Fixed unpickled documents replacing the global field's list. #888
- Fixed storage of microseconds in ComplexDateTimeField and unused separator option. #910 - Fixed storage of microseconds in ComplexDateTimeField and unused separator option. #910
- Django support was removed and will be available as a separate extension. #958 - Django support was removed and will be available as a separate extension. #958
- Don't send a "cls" option to ensureIndex (related to https://jira.mongodb.org/browse/SERVER-769)
Changes in 0.9.0 Changes in 0.9.0
================ ================

View File

@ -677,6 +677,12 @@ class Document(BaseDocument):
cls_indexed = cls_indexed or includes_cls(fields) cls_indexed = cls_indexed or includes_cls(fields)
opts = index_opts.copy() opts = index_opts.copy()
opts.update(spec) opts.update(spec)
# we shouldn't pass 'cls' to the collection.ensureIndex options
# because of https://jira.mongodb.org/browse/SERVER-769
if 'cls' in opts:
del opts['cls']
collection.ensure_index(fields, background=background, collection.ensure_index(fields, background=background,
drop_dups=drop_dups, **opts) drop_dups=drop_dups, **opts)
@ -684,6 +690,12 @@ class Document(BaseDocument):
# only if another index doesn't begin with _cls # only if another index doesn't begin with _cls
if (index_cls and not cls_indexed and if (index_cls and not cls_indexed and
cls._meta.get('allow_inheritance', ALLOW_INHERITANCE) is True): cls._meta.get('allow_inheritance', ALLOW_INHERITANCE) is True):
# we shouldn't pass 'cls' to the collection.ensureIndex options
# because of https://jira.mongodb.org/browse/SERVER-769
if 'cls' in index_opts:
del index_opts['cls']
collection.ensure_index('_cls', background=background, collection.ensure_index('_cls', background=background,
**index_opts) **index_opts)

View File

@ -826,5 +826,63 @@ class IndexesTest(unittest.TestCase):
post2 = BlogPost(title='test2', slug='test') post2 = BlogPost(title='test2', slug='test')
self.assertRaises(NotUniqueError, post2.save) self.assertRaises(NotUniqueError, post2.save)
def test_index_dont_send_cls_option(self):
"""
Ensure that 'cls' option is not sent through ensureIndex. We shouldn't
send internal MongoEngine arguments that are not a part of the index
spec.
This is directly related to the fact that MongoDB doesn't validate the
options that are passed to ensureIndex. For more details, see:
https://jira.mongodb.org/browse/SERVER-769
"""
class TestDoc(Document):
txt = StringField()
meta = {
'allow_inheritance': True,
'indexes': [
{ 'fields': ('txt',), 'cls': False }
]
}
class TestChildDoc(TestDoc):
txt2 = StringField()
meta = {
'indexes': [
{ 'fields': ('txt2',), 'cls': False }
]
}
TestDoc.drop_collection()
TestDoc.ensure_indexes()
TestChildDoc.ensure_indexes()
index_info = TestDoc._get_collection().index_information()
for key in index_info:
del index_info[key]['v'] # drop the index version - we don't care about that here
self.assertEqual(index_info, {
'txt_1': {
'key': [('txt', 1)],
'dropDups': False,
'background': False
},
'_id_': {
'key': [('_id', 1)],
},
'txt2_1': {
'key': [('txt2', 1)],
'dropDups': False,
'background': False
},
'_cls_1': {
'key': [('_cls', 1)],
'background': False,
}
})
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()