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

Function no_dereference

mongoengine/context_managers.py:133–162  ·  view source on GitHub ↗

no_dereference context manager. Turns off all dereferencing in Documents for the duration of the context manager:: with no_dereference(Group): Group.objects()

(cls)

Source from the content-addressed store, hash-verified

131
132@contextlib.contextmanager
133def no_dereference(cls):
134 """no_dereference context manager.
135
136 Turns off all dereferencing in Documents for the duration of the context
137 manager::
138
139 with no_dereference(Group):
140 Group.objects()
141 """
142 try:
143 cls = cls
144
145 ReferenceField = _import_class("ReferenceField")
146 GenericReferenceField = _import_class("GenericReferenceField")
147 ComplexBaseField = _import_class("ComplexBaseField")
148
149 deref_fields = [
150 field
151 for name, field in cls._fields.items()
152 if isinstance(
153 field, (ReferenceField, GenericReferenceField, ComplexBaseField)
154 )
155 ]
156
157 _register_no_dereferencing_for_class(cls)
158
159 with _no_dereference_for_fields(*deref_fields):
160 yield None
161 finally:
162 _unregister_no_dereferencing_for_class(cls)
163
164
165class no_sub_classes:

Calls 5

_import_classFunction · 0.90
itemsMethod · 0.80