Skip to content

Commit d4619bd

Browse files
committed
INTPYTHON-617 - Improve DictField to_python performance
1 parent 2931801 commit d4619bd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mongoengine/fields.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ def key_starts_with_dollar(d):
10381038
return True
10391039

10401040

1041-
# TODO: make a LazyDictField that lazily deferences on access
10421041
class DictField(ComplexBaseField):
10431042
"""A dictionary field that wraps a standard Python dictionary. This is
10441043
similar to an embedded document, but the structure is not defined.
@@ -1092,6 +1091,14 @@ def prepare_query_value(self, op, value):
10921091

10931092
return super().prepare_query_value(op, value)
10941093

1094+
def to_python(self, value):
1095+
to_python = getattr(self.field, "to_python", None)
1096+
return (
1097+
{k: to_python(v) for k, v in value.items()}
1098+
if to_python and value
1099+
else value or None
1100+
)
1101+
10951102

10961103
class LazyDictField(ComplexBaseField):
10971104
"""A lazy dictionary field that wraps a standard Python dictionary.

0 commit comments

Comments
 (0)