MCPcopy
hub / github.com/tortoise/tortoise-orm / validate

Method validate

tortoise/fields/base.py:327–343  ·  view source on GitHub ↗

Validate whether given value is valid :param value: Value to be validation :raises ValidationError: If validator check is not passed

(self, value: Any)

Source from the content-addressed store, hash-verified

325 return value
326
327 def validate(self, value: Any) -> None:
328 """
329 Validate whether given value is valid
330
331 :param value: Value to be validation
332 :raises ValidationError: If validator check is not passed
333 """
334 for v in self.validators:
335 if self.null and value is None:
336 continue
337 try:
338 if isinstance(value, Enum):
339 v(value.value)
340 else:
341 v(value)
342 except ValidationError as exc:
343 raise ValidationError(f"{self.model_field_name}: {exc}")
344
345 def has_db_default(self) -> bool:
346 return not isinstance(self.db_default, _DB_DEFAULT_NOT_SET)

Callers 10

to_db_valueMethod · 0.95
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80
to_db_valueMethod · 0.80

Calls 1

ValidationErrorClass · 0.90

Tested by

no test coverage detected