Fixed geo index creation bug

fixes MongoEngine/mongoengine#36
This commit is contained in:
Ross Lawley 2012-07-19 11:39:52 +01:00
parent 87ba69d02e
commit 1e51180d42
4 changed files with 23 additions and 8 deletions

View File

@ -4,6 +4,7 @@ Changelog
Changes in 0.6.15 Changes in 0.6.15
================= =================
- Fixed geo index creation through reference fields
- Added support for args / kwargs when using @queryset_manager - Added support for args / kwargs when using @queryset_manager
- Deref list custom id fix - Deref list custom id fix

View File

@ -1113,7 +1113,11 @@ Invalid data to create a `%s` instance.\n%s""".strip() % (cls._class_name, error
inspected = inspected or [] inspected = inspected or []
geo_indices = [] geo_indices = []
inspected.append(cls) inspected.append(cls)
from fields import EmbeddedDocumentField, GeoPointField
for field in cls._fields.values(): for field in cls._fields.values():
if not isinstance(field, (EmbeddedDocumentField, GeoPointField)):
continue
if hasattr(field, 'document_type'): if hasattr(field, 'document_type'):
field_cls = field.document_type field_cls = field.document_type
if field_cls in inspected: if field_cls in inspected:

View File

@ -483,7 +483,6 @@ class QuerySet(object):
self._collection.ensure_index(index_spec, self._collection.ensure_index(index_spec,
background=background, **index_opts) background=background, **index_opts)
@classmethod @classmethod
def _build_index_spec(cls, doc_cls, spec): def _build_index_spec(cls, doc_cls, spec):
"""Build a PyMongo index spec from a MongoEngine index spec. """Build a PyMongo index spec from a MongoEngine index spec.

View File

@ -872,15 +872,26 @@ class DocumentTest(unittest.TestCase):
def test_geo_indexes_recursion(self): def test_geo_indexes_recursion(self):
class User(Document): class Location(Document):
channel = ReferenceField('Channel') name = StringField()
location = GeoPointField() location = GeoPointField()
class Channel(Document): class Parent(Document):
user = ReferenceField('User') name = StringField()
location = GeoPointField() location = ReferenceField(Location)
self.assertEquals(len(User._geo_indices()), 2) Location.drop_collection()
Parent.drop_collection()
list(Parent.objects)
collection = Parent._get_collection()
info = collection.index_information()
self.assertFalse('location_2d' in info)
self.assertEquals(len(Parent._geo_indices()), 0)
self.assertEquals(len(Location._geo_indices()), 1)
def test_covered_index(self): def test_covered_index(self):
"""Ensure that covered indexes can be used """Ensure that covered indexes can be used
@ -3170,7 +3181,7 @@ name: Field is required ("name")"""
class Person(BasePerson): class Person(BasePerson):
name = StringField(required=True) name = StringField(required=True)
p = Person(age=15) p = Person(age=15)
self.assertRaises(ValidationError, p.validate) self.assertRaises(ValidationError, p.validate)