Merge pull request #1346 from anih/master

Speed up checking if we passed missing field
This commit is contained in:
Jérôme Lafréchoux 2016-09-06 09:51:33 +02:00 committed by GitHub
commit 3dc81058a0

View File

@ -72,12 +72,13 @@ class BaseDocument(object):
# Check if there are undefined fields supplied to the constructor, # Check if there are undefined fields supplied to the constructor,
# if so raise an Exception. # if so raise an Exception.
if not self._dynamic and (self._meta.get('strict', True) or _created): if not self._dynamic and (self._meta.get('strict', True) or _created):
for var in values.keys(): _undefined_fields = set(values.keys()) - set(
if var not in self._fields.keys() + ['id', 'pk', '_cls', '_text_score']: self._fields.keys() + ['id', 'pk', '_cls', '_text_score'])
msg = ( if _undefined_fields:
"The field '{0}' does not exist on the document '{1}'" msg = (
).format(var, self._class_name) "The fields '{0}' do not exist on the document '{1}'"
raise FieldDoesNotExist(msg) ).format(_undefined_fields, self._class_name)
raise FieldDoesNotExist(msg)
if self.STRICT and not self._dynamic: if self.STRICT and not self._dynamic:
self._data = StrictDict.create(allowed_keys=self._fields_ordered)() self._data = StrictDict.create(allowed_keys=self._fields_ordered)()