Helpers

A collection of useful convenience methods.

class odin.helpers.ValidationErrorCollection[source]

Helper collection for collecting validation error messages and generating or raising an exception.

Usage:

errors = ValidationErrorCollection()
... # Perform validation
errors.add_message("name", "Value is required")

if errors:
    raise errors.validation_error()
add_message(field: Union[str, odin.fields.base.BaseField], *messages)[source]

Append validation error message(s).

add_resource_message(*messages)[source]

Append resource level validation error message(s).

messages

Filtered messages that strips out empty messages.

raise_if_defined()[source]

Raise an exception if any are defined.

validation_error() → odin.exceptions.ValidationError[source]

Generate an exception based on the validation messages added.