dont send a "cls" option to ensureIndex (related to https://jira.mongodb.org/browse/SERVER-769)
This commit is contained in:
parent
d9c8285806
commit
9bdc320cf8
3
AUTHORS
3
AUTHORS
@ -119,7 +119,7 @@ that much better:
|
||||
* Anton Kolechkin
|
||||
* Sergey Nikitin
|
||||
* psychogenic
|
||||
* Stefan Wójcik
|
||||
* Stefan Wójcik (https://github.com/wojcikstefan)
|
||||
* dimonb
|
||||
* Garry Polley
|
||||
* James Slagle
|
||||
@ -138,7 +138,6 @@ that much better:
|
||||
* hellysmile
|
||||
* Jaepil Jeong
|
||||
* Daniil Sharou
|
||||
* Stefan Wójcik
|
||||
* Pete Campton
|
||||
* Martyn Smith
|
||||
* Marcelo Anton
|
||||
|
@ -14,6 +14,7 @@ Changes in 0.9.X - DEV
|
||||
- Fixed unpickled documents replacing the global field's list. #888
|
||||
- Fixed storage of microseconds in ComplexDateTimeField and unused separator option. #910
|
||||
- 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
|
||||
================
|
||||
|
@ -677,6 +677,12 @@ class Document(BaseDocument):
|
||||
cls_indexed = cls_indexed or includes_cls(fields)
|
||||
opts = index_opts.copy()
|
||||
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,
|
||||
drop_dups=drop_dups, **opts)
|
||||
|
||||
@ -684,6 +690,12 @@ class Document(BaseDocument):
|
||||
# only if another index doesn't begin with _cls
|
||||
if (index_cls and not cls_indexed and
|
||||
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,
|
||||
**index_opts)
|
||||
|
||||
|
@ -826,5 +826,63 @@ class IndexesTest(unittest.TestCase):
|
||||
post2 = BlogPost(title='test2', slug='test')
|
||||
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__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user