fix-#733: index_cls is ignored when deciding to set _cls as index prefix

This commit is contained in:
DavidBord 2014-08-17 11:19:18 +03:00
parent bb7e5f17b5
commit 46da918dbe
2 changed files with 13 additions and 0 deletions

View File

@ -718,6 +718,9 @@ class BaseDocument(object):
ALLOW_INHERITANCE)
include_cls = (allow_inheritance and not spec.get('sparse', False) and
spec.get('cls', True))
# 733: don't include cls if index_cls is False unless there is an explicit cls with the index
include_cls = include_cls and (spec.get('cls', False) or cls._meta.get('index_cls', True))
if "cls" in spec:
spec.pop('cls')
for key in spec['fields']:

View File

@ -175,6 +175,16 @@ class IndexesTest(unittest.TestCase):
info = A._get_collection().index_information()
self.assertEqual(len(info.keys()), 2)
class B(A):
c = StringField()
d = StringField()
meta = {
'indexes': [{'fields': ['c']}, {'fields': ['d'], 'cls': True}],
'allow_inheritance': True
}
self.assertEqual([('c', 1)], B._meta['index_specs'][1]['fields'])
self.assertEqual([('_cls', 1), ('d', 1)], B._meta['index_specs'][2]['fields'])
def test_build_index_spec_is_not_destructive(self):
class MyDoc(Document):