-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
i encountered an issue when i was using DynamicDocument, here is the situation
In [1]: import mongoengine as models
In [2]: models.connect(port=11111)
Out[2]: MongoClient('localhost', 11111)
In [3]: class Foo(models.DynamicDocument):
pass
...:
In [4]: Foo.objects.delete()
Out[4]: 1
In [5]: foo = Foo.objects.create()
In [6]: foo._data
Out[6]: {'id': ObjectId('55910f4a53a70c17c0e2eb5e')}
In [7]: foo.update(bar=1)
Out[7]: 1
In [8]: foo._data
Out[8]: {'id': ObjectId('55910f4a53a70c17c0e2eb5e')}
In [9]: foo.reload()
Out[9]: <Foo: Foo object>
In [10]: foo._data
Out[10]: {'id': ObjectId('55910f4a53a70c17c0e2eb5e')}
In [11]: foo._dyn
foo._dynamic foo._dynamic_fields foo._dynamic_lock
In [11]: foo._dynamic_fields
Out[11]: SON([])
In [12]: foo._fields_ordered
Out[12]: ('id',)and it supposed to had bar reloaded, something like
{'bar': 1, 'id': ObjectId('55910f4a53a70c17c0e2eb5e')}
in https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/document.py#L591 we can see that it loops over self._fields_ordered, which unfortunately DynamicDocument havn't
the simplest way i think is just loop over obj._data since obj is a complete instance