Fix QuerySet.ensure_index for new index specs
This commit is contained in:
		| @@ -376,9 +376,13 @@ class QuerySet(object): | |||||||
|             construct a multi-field index); keys may be prefixed with a **+** |             construct a multi-field index); keys may be prefixed with a **+** | ||||||
|             or a **-** to determine the index ordering |             or a **-** to determine the index ordering | ||||||
|         """ |         """ | ||||||
|         index_list = QuerySet._build_index_spec(self._document, key_or_list) |         index_spec = QuerySet._build_index_spec(self._document, key_or_list) | ||||||
|         self._collection.ensure_index(index_list, drop_dups=drop_dups, |         self._collection.ensure_index( | ||||||
|             background=background) |             index_spec['fields'],  | ||||||
|  |             drop_dups=drop_dups, | ||||||
|  |             background=background, | ||||||
|  |             sparse=index_spec.get('sparse', False), | ||||||
|  |             unique=index_spec.get('unique', False)) | ||||||
|         return self |         return self | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|   | |||||||
| @@ -2099,6 +2099,22 @@ class QuerySetTest(unittest.TestCase): | |||||||
|         Number.drop_collection() |         Number.drop_collection() | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     def test_ensure_index(self): | ||||||
|  |         """Ensure that manual creation of indexes works. | ||||||
|  |         """ | ||||||
|  |         class Comment(Document): | ||||||
|  |             message = StringField() | ||||||
|  |  | ||||||
|  |         Comment.objects.ensure_index('message') | ||||||
|  |  | ||||||
|  |         info = Comment.objects._collection.index_information() | ||||||
|  |         info = [(value['key'], | ||||||
|  |                  value.get('unique', False), | ||||||
|  |                  value.get('sparse', False)) | ||||||
|  |                 for key, value in info.iteritems()] | ||||||
|  |         self.assertTrue(([('_types', 1), ('message', 1)], False, False) in info) | ||||||
|  |  | ||||||
|  |  | ||||||
| class QTest(unittest.TestCase): | class QTest(unittest.TestCase): | ||||||
|  |  | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user