MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / __get__

Method __get__

mongoengine/fields.py:1188–1207  ·  view source on GitHub ↗

Descriptor to allow lazy dereferencing.

(self, instance, owner)

Source from the content-addressed store, hash-verified

1186 return ref_cls._from_son(dereferenced_son)
1187
1188 def __get__(self, instance, owner):
1189 """Descriptor to allow lazy dereferencing."""
1190 if instance is None:
1191 # Document class being used rather than a document object
1192 return self
1193
1194 # Get value from document instance if available
1195 ref_value = instance._data.get(self.name)
1196 auto_dereference = instance._fields[self.name]._auto_dereference
1197 # Dereference DBRefs
1198 if auto_dereference and isinstance(ref_value, DBRef):
1199 if hasattr(ref_value, "cls"):
1200 # Dereference using the class type specified in the reference
1201 cls = get_document(ref_value.cls)
1202 else:
1203 cls = self.document_type
1204
1205 instance._data[self.name] = self._lazy_load_ref(cls, ref_value)
1206
1207 return super().__get__(instance, owner)
1208
1209 def to_mongo(self, document):
1210 if isinstance(document, DBRef):

Callers

nothing calls this directly

Calls 4

_lazy_load_refMethod · 0.95
get_documentFunction · 0.90
getMethod · 0.45
__get__Method · 0.45

Tested by

no test coverage detected