|
16 | 16 | from bson.decimal128 import Decimal128, create_decimal128_context |
17 | 17 | from pymongo import ReturnDocument |
18 | 18 |
|
19 | | -from mongoengine.base.datastructures import RawDict |
20 | | - |
21 | 19 | try: |
22 | 20 | import dateutil |
23 | 21 | except ImportError: |
|
83 | 81 | "SortedListField", |
84 | 82 | "EmbeddedDocumentListField", |
85 | 83 | "DictField", |
86 | | - "LazyDictField", |
87 | 84 | "MapField", |
88 | 85 | "ReferenceField", |
89 | 86 | "CachedReferenceField", |
@@ -1100,66 +1097,6 @@ def to_python(self, value): |
1100 | 1097 | ) |
1101 | 1098 |
|
1102 | 1099 |
|
1103 | | -class LazyDictField(ComplexBaseField): |
1104 | | - """A lazy dictionary field that wraps a standard Python dictionary. |
1105 | | - Unlike the :class:`~mongoengine.fields.DictField`, it will |
1106 | | - **not** be automatically deserialized. Manual deserialization must be triggered |
1107 | | - using the ``deserialize()`` method. |
1108 | | -
|
1109 | | - .. note:: |
1110 | | - Required means it cannot be empty - as the default for DictFields is {} |
1111 | | - """ |
1112 | | - |
1113 | | - def __init__(self, field=None, *args, **kwargs): |
1114 | | - kwargs.setdefault("default", dict) |
1115 | | - super().__init__(*args, field=field, **kwargs) |
1116 | | - self.set_auto_dereferencing(False) |
1117 | | - |
1118 | | - def validate(self, value): |
1119 | | - """Make sure that a list of valid fields is being used.""" |
1120 | | - if not isinstance(value, dict): |
1121 | | - self.error("Only dictionaries may be used in a DictField") |
1122 | | - |
1123 | | - if key_not_string(value): |
1124 | | - msg = "Invalid dictionary key - documents must have only string keys" |
1125 | | - self.error(msg) |
1126 | | - |
1127 | | - # Following condition applies to MongoDB >= 3.6 |
1128 | | - # older Mongo has stricter constraints but |
1129 | | - # it will be rejected upon insertion anyway |
1130 | | - # Having a validation that depends on the MongoDB version |
1131 | | - # is not straightforward as the field isn't aware of the connected Mongo |
1132 | | - if key_starts_with_dollar(value): |
1133 | | - self.error( |
1134 | | - 'Invalid dictionary key name - keys may not startswith "$" characters' |
1135 | | - ) |
1136 | | - super().validate(value) |
1137 | | - |
1138 | | - def lookup_member(self, member_name): |
1139 | | - return DictField(db_field=member_name) |
1140 | | - |
1141 | | - def prepare_query_value(self, op, value): |
1142 | | - match_operators = [*STRING_OPERATORS] |
1143 | | - |
1144 | | - if op in match_operators and isinstance(value, str): |
1145 | | - return StringField().prepare_query_value(op, value) |
1146 | | - |
1147 | | - if hasattr( |
1148 | | - self.field, "field" |
1149 | | - ): # Used for instance when using DictField(ListField(IntField())) |
1150 | | - if op in ("set", "unset") and isinstance(value, dict): |
1151 | | - return { |
1152 | | - k: self.field.prepare_query_value(op, v) for k, v in value.items() |
1153 | | - } |
1154 | | - return self.field.prepare_query_value(op, value) |
1155 | | - |
1156 | | - return super().prepare_query_value(op, value) |
1157 | | - |
1158 | | - def to_python(self, value): |
1159 | | - self._data = RawDict(value, super().to_python) |
1160 | | - return self._data |
1161 | | - |
1162 | | - |
1163 | 1100 | class MapField(DictField): |
1164 | 1101 | """A field that maps a name to a specified field type. Similar to |
1165 | 1102 | a DictField, except the 'value' of each item must match the specified |
|
0 commit comments