From 2bfb195ad671aee104111f3fe2a324530df6b1d3 Mon Sep 17 00:00:00 2001 From: Axel Haustant Date: Mon, 13 Apr 2015 18:07:48 +0200 Subject: [PATCH] Document FieldDoesNotExist and meta.strict --- docs/apireference.rst | 3 +++ mongoengine/document.py | 5 +++++ mongoengine/errors.py | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/apireference.rst b/docs/apireference.rst index 7ba93408..625d4a8b 100644 --- a/docs/apireference.rst +++ b/docs/apireference.rst @@ -34,6 +34,9 @@ Documents .. autoclass:: mongoengine.ValidationError :members: +.. autoclass:: mongoengine.FieldDoesNotExist + + Context Managers ================ diff --git a/mongoengine/document.py b/mongoengine/document.py index eea5dabc..f8275021 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -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 diff --git a/mongoengine/errors.py b/mongoengine/errors.py index 6cde7771..a411ac47 100644 --- a/mongoengine/errors.py +++ b/mongoengine/errors.py @@ -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):