(cls, model, mask_secrets=False)
| 86 | |
| 87 | @classmethod |
| 88 | def _from_model(cls, model, mask_secrets=False): |
| 89 | doc = model.to_mongo() |
| 90 | |
| 91 | if "_id" in doc: |
| 92 | doc["id"] = str(doc.pop("_id")) |
| 93 | |
| 94 | # Special case for models which utilize JSONDictField - there is no need to escape those |
| 95 | # fields since it contains a JSON string and not a dictionary which doesn't need to be |
| 96 | # mongo escaped. Skipping this step here substantially speeds things up for that field. |
| 97 | |
| 98 | # Right now we do this here manually for all those fields types but eventually we should |
| 99 | # refactor the code to just call unescape chars on escaped fields - more generic and |
| 100 | # faster. |
| 101 | raw_values = {} |
| 102 | |
| 103 | for field_name in cls.skip_unescape_field_names: |
| 104 | if isinstance(doc.get(field_name, None), bytes): |
| 105 | raw_values[field_name] = doc.pop(field_name) |
| 106 | |
| 107 | # TODO (Tomaz): In general we really shouldn't need to call unescape chars on the whole doc, |
| 108 | # but just on the EscapedDict and EscapedDynamicField fields - doing it on the whole doc |
| 109 | # level is slow and not necessary! |
| 110 | doc = util_mongodb.unescape_chars(doc) |
| 111 | |
| 112 | # Now add the JSON string field value which shouldn't be escaped back. |
| 113 | # We don't JSON parse the field value here because that happens inside the model specific |
| 114 | # "from_model()" method where we also parse and convert all the other field values. |
| 115 | for field_name, field_value in raw_values.items(): |
| 116 | doc[field_name] = field_value |
| 117 | |
| 118 | if mask_secrets and cfg.CONF.log.mask_secrets: |
| 119 | doc = model.mask_secrets(value=doc) |
| 120 | |
| 121 | return doc |
| 122 | |
| 123 | @classmethod |
| 124 | def from_model(cls, model, mask_secrets=False): |
no test coverage detected