From 3534bf7d70210616c9d997260f2725596951557e Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Tue, 4 Sep 2012 08:20:19 +0100 Subject: [PATCH] Fixed index spec inheritance (MongoEngine/mongoengine#111) --- docs/changelog.rst | 4 ++++ mongoengine/queryset.py | 4 ++++ tests/test_document.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6cfdbf6b..c2a5cb47 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,10 @@ Changelog ========= +Changes in 0.7.1 +================= +- Fixed index spec inheritance (MongoEngine/mongoengine#111) + Changes in 0.7.0 ================= - Updated queryset.delete so you can use with skip / limit (MongoEngine/mongoengine#107) diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 8106e67e..b020209b 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -510,6 +510,10 @@ class QuerySet(object): use_types = allow_inheritance and not spec.get('sparse', False) for key in spec['fields']: + # If inherited spec continue + if isinstance(key, (list, tuple)): + continue + # Get ASCENDING direction from +, DESCENDING from -, and GEO2D from * direction = pymongo.ASCENDING if key.startswith("-"): diff --git a/tests/test_document.py b/tests/test_document.py index 75616c77..976a2731 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -669,6 +669,25 @@ class DocumentTest(unittest.TestCase): BlogPost.drop_collection() + def test_inherited_index(self): + """Ensure index specs are inhertited correctly""" + + class A(Document): + title = StringField() + meta = { + 'indexes': [ + { + 'fields': ('title',), + }, + ], + 'allow_inheritance': True, + } + + class B(A): + description = StringField() + + self.assertEqual(A._meta['index_specs'], B._meta['index_specs']) + def test_db_field_load(self): """Ensure we load data correctly """