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

Method _validate

mongoengine/base/fields.py:266–292  ·  view source on GitHub ↗
(self, value, **kwargs)

Source from the content-addressed store, hash-verified

264 self.error("Value must be one of %s" % str(choice_list))
265
266 def _validate(self, value, **kwargs):
267 # Check the Choices Constraint
268 if self.choices:
269 self._validate_choices(value)
270
271 # check validation argument
272 if self.validation is not None:
273 if callable(self.validation):
274 try:
275 # breaking change of 0.18
276 # Get rid of True/False-type return for the validation method
277 # in favor of having validation raising a ValidationError
278 ret = self.validation(value)
279 if ret is not None:
280 raise DeprecatedError(
281 "validation argument for `%s` must not return anything, "
282 "it should raise a ValidationError if validation fails"
283 % self.name
284 )
285 except ValidationError as ex:
286 self.error(str(ex))
287 else:
288 raise ValueError(
289 'validation argument for `"%s"` must be a ' "callable." % self.name
290 )
291
292 self.validate(value, **kwargs)
293
294 @property
295 def owner_document(self):

Callers 2

validateMethod · 0.80
validateMethod · 0.80

Calls 4

_validate_choicesMethod · 0.95
errorMethod · 0.95
validateMethod · 0.95
DeprecatedErrorClass · 0.90

Tested by

no test coverage detected