Fix index creation error that was swallowed by hasattr under python2 (#1688)

This commit is contained in:
Bastien Gérard
2018-08-29 23:04:18 +02:00
parent 9ad959a478
commit b4860de34d
2 changed files with 27 additions and 5 deletions

View File

@@ -133,7 +133,12 @@ class DeReference(object):
"""
object_map = {}
for collection, dbrefs in self.reference_map.iteritems():
if hasattr(collection, 'objects'): # We have a document class for the refs
# we use getattr instead of hasattr because as hasattr swallows any exception under python2
# so it could hide nasty things without raising exceptions (cfr bug #1688))
ref_document_cls_exists = (getattr(collection, 'objects', None) is not None)
if ref_document_cls_exists:
col_name = collection._get_collection_name()
refs = [dbref for dbref in dbrefs
if (col_name, dbref) not in object_map]