@@ -47,14 +47,14 @@ def __init__(self, *args, **values):
4747 """
4848 Initialise a document or an embedded document.
4949
50- :param values: A dictionary of keys and values for the document.
50+ :param dict values: A dictionary of keys and values for the document.
5151 It may contain additional reserved keywords, e.g. "__auto_convert".
52- :param __auto_convert: If True, supplied values will be converted
52+ :param bool __auto_convert: If True, supplied values will be converted
5353 to Python-type values via each field's `to_python` method.
54- :param __only_fields: A list of fields that have been loaded for this
55- document. Empty if all fields have been loaded.
56- :param _created: Indicates whether this is a brand new document or
57- whether it's already been persisted before. Defaults to true.
54+ :param set __only_fields: A set of fields that have been loaded for
55+ this document. Empty if all fields have been loaded.
56+ :param bool _created: Indicates whether this is a brand new document
57+ or whether it's already been persisted before. Defaults to true.
5858 """
5959 self ._initialised = False
6060 self ._created = True
@@ -75,7 +75,6 @@ def __init__(self, *args, **values):
7575
7676 __auto_convert = values .pop ('__auto_convert' , True )
7777
78- # 399: set default values only to fields loaded from DB
7978 __only_fields = set (values .pop ('__only_fields' , values ))
8079
8180 _created = values .pop ('_created' , True )
@@ -100,7 +99,9 @@ def __init__(self, *args, **values):
10099
101100 self ._dynamic_fields = SON ()
102101
103- # Assign default values to instance
102+ # Assign default values to the instance.
103+ # We set default values only for fields loaded from DB. See
104+ # https://github.com/mongoengine/mongoengine/issues/399 for more info.
104105 for key , field in iteritems (self ._fields ):
105106 if self ._db_field_map .get (key , key ) in __only_fields :
106107 continue
0 commit comments