Merge pull request #957 from noirbizarre/metastrict
Allow to loads undeclared field with meta attribute (fix #934)
This commit is contained in:
@@ -70,9 +70,9 @@ class BaseDocument(object):
|
||||
|
||||
signals.pre_init.send(self.__class__, document=self, values=values)
|
||||
|
||||
# Check if there are undefined fields supplied, if so raise an
|
||||
# Exception.
|
||||
if not self._dynamic:
|
||||
# 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']:
|
||||
msg = (
|
||||
|
||||
@@ -135,6 +135,11 @@ class Document(BaseDocument):
|
||||
doesn't contain a list) if allow_inheritance is True. This can be
|
||||
disabled by either setting cls to False on the specific index or
|
||||
by setting index_cls to False on the meta dictionary for the document.
|
||||
|
||||
By default, any extra attribute existing in stored data but not declared
|
||||
in your model will raise a :class:`~mongoengine.FieldDoesNotExist` error.
|
||||
This can be disabled by setting :attr:`strict` to ``False``
|
||||
in the :attr:`meta` dictionnary.
|
||||
"""
|
||||
|
||||
# The __metaclass__ attribute is removed by 2to3 when running with Python3
|
||||
|
||||
@@ -42,7 +42,14 @@ class NotUniqueError(OperationError):
|
||||
|
||||
|
||||
class FieldDoesNotExist(Exception):
|
||||
pass
|
||||
"""Raised when trying to set a field
|
||||
not declared in a :class:`~mongoengine.Document`
|
||||
or an :class:`~mongoengine.EmbeddedDocument`.
|
||||
|
||||
To avoid this behavior on data loading,
|
||||
you should the :attr:`strict` to ``False``
|
||||
in the :attr:`meta` dictionnary.
|
||||
"""
|
||||
|
||||
|
||||
class ValidationError(AssertionError):
|
||||
|
||||
Reference in New Issue
Block a user