Make sure that a list of valid fields is being used.
(self, value)
| 1044 | self.set_auto_dereferencing(False) |
| 1045 | |
| 1046 | def validate(self, value): |
| 1047 | """Make sure that a list of valid fields is being used.""" |
| 1048 | if not isinstance(value, dict): |
| 1049 | self.error("Only dictionaries may be used in a DictField") |
| 1050 | |
| 1051 | if key_not_string(value): |
| 1052 | msg = "Invalid dictionary key - documents must have only string keys" |
| 1053 | self.error(msg) |
| 1054 | |
| 1055 | # Following condition applies to MongoDB >= 3.6 |
| 1056 | # older Mongo has stricter constraints but |
| 1057 | # it will be rejected upon insertion anyway |
| 1058 | # Having a validation that depends on the MongoDB version |
| 1059 | # is not straightforward as the field isn't aware of the connected Mongo |
| 1060 | if key_starts_with_dollar(value): |
| 1061 | self.error( |
| 1062 | 'Invalid dictionary key name - keys may not startswith "$" characters' |
| 1063 | ) |
| 1064 | super().validate(value) |
| 1065 | |
| 1066 | def lookup_member(self, member_name): |
| 1067 | return DictField(db_field=member_name) |
nothing calls this directly
no test coverage detected