Skip to content

Commit f2fe58c

Browse files
committed
Added a condition to store data to ObjectDict when the items type is it
Previous dereference implementation re-contains data as `dict` except for the predicted type. But the OrderedDict is not predicted, so the its data would be converted `dict` implicitly. As the result, the order of stored data get wrong. And this patch prevents it.
1 parent 6aaf9ba commit f2fe58c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mongoengine/dereference.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from bson import DBRef, SON
23
import six
34

@@ -201,6 +202,10 @@ def _attach_objects(self, items, depth=0, instance=None, name=None):
201202
as_tuple = isinstance(items, tuple)
202203
iterator = enumerate(items)
203204
data = []
205+
elif type(items) == OrderedDict:
206+
is_list = False
207+
iterator = items.iteritems()
208+
data = OrderedDict()
204209
else:
205210
is_list = False
206211
iterator = items.iteritems()

0 commit comments

Comments
 (0)