Speed up checking if we passed missing field

This commit is contained in:
anih 2016-07-27 12:10:46 +02:00 committed by GitHub
parent 488684d960
commit 40e99b1b80

View File

@ -72,11 +72,12 @@ 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(): _missing_fields_keys = set(values.keys()) - set(
if var not in self._fields.keys() + ['id', 'pk', '_cls', '_text_score']: self._fields.keys() + ['id', 'pk', '_cls', '_text_score'])
if _missing_fields_keys:
msg = ( msg = (
"The field '{0}' does not exist on the document '{1}'" "The fields '{0}' does not exist on the document '{1}'"
).format(var, self._class_name) ).format(_missing_fields_keys, self._class_name)
raise FieldDoesNotExist(msg) raise FieldDoesNotExist(msg)
if self.STRICT and not self._dynamic: if self.STRICT and not self._dynamic: