Fixed infinite recursion bug in _geo_indices()
Fixes #213 Thanks to joshink for the bug report
This commit is contained in:
parent
d51d95a28e
commit
8e1d701c27
@ -754,11 +754,16 @@ class BaseDocument(object):
|
||||
return set_data, unset_data
|
||||
|
||||
@classmethod
|
||||
def _geo_indices(cls):
|
||||
def _geo_indices(cls, inspected_classes=None):
|
||||
inspected_classes = inspected_classes or []
|
||||
geo_indices = []
|
||||
inspected_classes.append(cls)
|
||||
for field in cls._fields.values():
|
||||
if hasattr(field, 'document_type'):
|
||||
geo_indices += field.document_type._geo_indices()
|
||||
field_cls = field.document_type
|
||||
if field_cls in inspected_classes:
|
||||
continue
|
||||
geo_indices += field_cls._geo_indices(inspected_classes)
|
||||
elif field._geo_index:
|
||||
geo_indices.append(field)
|
||||
return geo_indices
|
||||
|
@ -662,6 +662,18 @@ class DocumentTest(unittest.TestCase):
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
def test_geo_indexes_recursion(self):
|
||||
|
||||
class User(Document):
|
||||
channel = ReferenceField('Channel')
|
||||
location = GeoPointField()
|
||||
|
||||
class Channel(Document):
|
||||
user = ReferenceField('User')
|
||||
location = GeoPointField()
|
||||
|
||||
self.assertEquals(len(User._geo_indices()), 2)
|
||||
|
||||
def test_hint(self):
|
||||
|
||||
class BlogPost(Document):
|
||||
|
Loading…
x
Reference in New Issue
Block a user