From 09d7ae4f804096ab4d8f13fac5c6f1a862b9a12b Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Mon, 17 Jun 2019 14:52:26 +0200 Subject: [PATCH] More BaseDocument.__init__ documentation tweaks --- mongoengine/base/document.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mongoengine/base/document.py b/mongoengine/base/document.py index cebcf337..057258f5 100644 --- a/mongoengine/base/document.py +++ b/mongoengine/base/document.py @@ -47,14 +47,14 @@ class BaseDocument(object): """ Initialise a document or an embedded document. - :param values: A dictionary of keys and values for the document. + :param dict values: A dictionary of keys and values for the document. It may contain additional reserved keywords, e.g. "__auto_convert". - :param __auto_convert: If True, supplied values will be converted + :param bool __auto_convert: If True, supplied values will be converted to Python-type values via each field's `to_python` method. - :param __only_fields: A list of fields that have been loaded for this - document. Empty if all fields have been loaded. - :param _created: Indicates whether this is a brand new document or - whether it's already been persisted before. Defaults to true. + :param set __only_fields: A set of fields that have been loaded for + this document. Empty if all fields have been loaded. + :param bool _created: Indicates whether this is a brand new document + or whether it's already been persisted before. Defaults to true. """ self._initialised = False self._created = True @@ -75,7 +75,6 @@ class BaseDocument(object): __auto_convert = values.pop('__auto_convert', True) - # 399: set default values only to fields loaded from DB __only_fields = set(values.pop('__only_fields', values)) _created = values.pop('_created', True) @@ -100,7 +99,9 @@ class BaseDocument(object): self._dynamic_fields = SON() - # Assign default values to instance + # Assign default values to the instance. + # We set default values only for fields loaded from DB. See + # https://github.com/mongoengine/mongoengine/issues/399 for more info. for key, field in iteritems(self._fields): if self._db_field_map.get(key, key) in __only_fields: continue