Descriptor to allow lazy dereferencing.
(self, instance, owner)
| 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): |
nothing calls this directly
no test coverage detected