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

Method __expand_dynamic_values

mongoengine/base/document.py:493–519  ·  view source on GitHub ↗

Expand any dynamic values to their correct types / values.

(self, name, value)

Source from the content-addressed store, hash-verified

491 return cls._from_son(json_util.loads(json_data, **kwargs), created=created)
492
493 def __expand_dynamic_values(self, name, value):
494 """Expand any dynamic values to their correct types / values."""
495 if not isinstance(value, (dict, list, tuple)):
496 return value
497
498 # If the value is a dict with '_cls' in it, turn it into a document
499 is_dict = isinstance(value, dict)
500 if is_dict and "_cls" in value:
501 cls = get_document(value["_cls"])
502 return cls(**value)
503
504 if is_dict:
505 value = {k: self.__expand_dynamic_values(k, v) for k, v in value.items()}
506 else:
507 value = [self.__expand_dynamic_values(name, v) for v in value]
508
509 # Convert lists / values so we can watch for any changes on them
510 EmbeddedDocumentListField = _import_class("EmbeddedDocumentListField")
511 if isinstance(value, (list, tuple)) and not isinstance(value, BaseList):
512 if issubclass(type(self), EmbeddedDocumentListField):
513 value = EmbeddedDocumentList(value, self, name)
514 else:
515 value = BaseList(value, self, name)
516 elif isinstance(value, dict) and not isinstance(value, BaseDict):
517 value = BaseDict(value, self, name)
518
519 return value
520
521 def _mark_as_changed(self, key):
522 """Mark a key as explicitly changed by the user."""

Callers 1

__setattr__Method · 0.95

Calls 6

get_documentFunction · 0.90
_import_classFunction · 0.90
BaseListClass · 0.90
BaseDictClass · 0.90
itemsMethod · 0.80

Tested by

no test coverage detected