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,
# if so raise an Exception.
if not self._dynamic and (self._meta.get('strict', True) or _created):
for var in values.keys():
if var not in self._fields.keys() + ['id', 'pk', '_cls', '_text_score']:
_missing_fields_keys = set(values.keys()) - set(
self._fields.keys() + ['id', 'pk', '_cls', '_text_score'])
if _missing_fields_keys:
msg = (
"The field '{0}' does not exist on the document '{1}'"
).format(var, self._class_name)
"The fields '{0}' does not exist on the document '{1}'"
).format(_missing_fields_keys, self._class_name)
raise FieldDoesNotExist(msg)
if self.STRICT and not self._dynamic: