We return a custom wrapper over dict which tracks changes to the dictionary and allows us to only write the field to the database on update if the field value has changed - very important since it means much more efficient partial updates.
(self, instance, owner)
| 491 | return compression_header.value + b":" + b"o:" + data |
| 492 | |
| 493 | def __get__(self, instance, owner): |
| 494 | """ |
| 495 | We return a custom wrapper over dict which tracks changes to the dictionary and allows us |
| 496 | to only write the field to the database on update if the field value has changed - very |
| 497 | important since it means much more efficient partial updates. |
| 498 | """ |
| 499 | value = super().__get__(instance, owner) |
| 500 | |
| 501 | if isinstance(value, dict) and not isinstance(value, BaseDict): |
| 502 | value = BaseDict(value, instance, self.name) |
| 503 | |
| 504 | # NOTE: It's important this attribute is set, since only this way mongoengine can determine |
| 505 | # if the field has chaned or not when determing if the value should be written to the db or |
| 506 | # not |
| 507 | if instance: |
| 508 | instance._data[self.name] = value |
| 509 | |
| 510 | return value |
| 511 | |
| 512 | |
| 513 | class JSONDictEscapedFieldCompatibilityField(JSONDictField): |