Exceptions#

exception oblate.OblateException#

Base class for all exceptions provided by Oblate.

exception oblate.FieldNotSet(field, schema, field_name)#

An exception raised when a field is accessed that has no value set.

This is raised in following circumstances only:

  • For fields that have required set to False and don’t have a value set.

  • Field accessed in a context when fields are not loaded yet. An example of this is the Schema.preprocess_data() method.

For a more Pythonic handling of this, this exception inherits the AttributeError exception.

name#

The name that was used to address the field. This could be different from the field’s attribute name if the field has a specific load key set.

Type:

str

field#

The field that was accessed but had no value set.

Type:

oblate.fields.Field

schema#

The schema that accessed the field.

Type:

Schema

exception oblate.FrozenError(entity)#

An exception raised when a frozen field or schema is updated.

entity#

The schema or field that was attempted to be updated.

Type:

Union[Schema, Field]

exception oblate.FieldError(message, /, state=None)#

An error raised when validation fails for a field.

This error when raised in validators or other user-side code is accounted as validation error and is included in the subsequent raised ValidationError.

For convenience, instead of raising this error directly, you should raise ValueError or AssertionError in your validators code which would automatically be wrapped as a field error.

Warning

It is recommended to raise ValueError if you intend to run your script using the Python’s -O or -OO optimization flags. These flags remove the assertion statements from the code causing the validators to stop working properly.

Parameters:
  • message – The error message. If this is a sequence, each element of sequence is accounted as a separate error.

  • state – The state to attach to this error. This parameter allows users to attach extra state that can be accessed later. Library will not be performing any manipulations on this value.

context#

The current context in which the error was raised. Could be None if no context exists.

Type:

Optional[Union[LoadContext, DumpContext]]

schema#

The schema that the error originates from.

Type:

Schema

property field#

The Field that caused the error.

If this returns None, it means that the causative field doesn’t exist. An example of this case is when an invalid field name is passed during schema initialization.

Type:

fields.Field

property key#

The key that points to the erroneous value in raw data.

This is essentially the name of field that has the error but may not always be a valid field name.

Type:

str

exception oblate.ValidationError(errors)#

An error raised when validation fails with one or more FieldError.

Parameters:
  • errors (List[FieldError]) – The errors that caused the validation failure.

  • schema (Schema) – The schema this error originates from.

raw()#

Converts the error into raw format.

The standard format returned by this method is a dictionary containing field names as keys and list of error messages as the value.

This method can be overriden to implement a custom format.

exception oblate.TypeValidationError(errors)#

An error raised when type validation fails.

This is raised by oblate.validate_types() method.

errors#

A dictionary with values representing list of type validation error messages for given key.

Type:

Dict[str, List[str]]