Skip to content

Errors Handling

ormdantic.errors.ConfigurationError

ConfigurationError(msg)

Bases: Exception

Raised for mal-configured database models or schemas.

Source code in ormdantic/errors.py
def __init__(self, msg: str):
    super().__init__(msg)

ormdantic.errors.UndefinedBackReferenceError

UndefinedBackReferenceError(table_a, table_b, field)

Bases: ConfigurationError

Raised when a back reference is missing from a table.

Source code in ormdantic/errors.py
def __init__(self, table_a: str, table_b: str, field: str) -> None:
    super().__init__(
        f'Many relation defined on "{table_a}.{field}" to table {table_b}" must be'
        f' defined with a back reference on "{table_a}".'
    )

ormdantic.errors.MismatchingBackReferenceError

MismatchingBackReferenceError(
    table_a, table_b, field, back_reference
)

Bases: ConfigurationError

Raised when a back reference is typed incorrectly.

Source code in ormdantic/errors.py
def __init__(
    self, table_a: str, table_b: str, field: str, back_reference: str
) -> None:
    super().__init__(
        f'Many relation defined on "{table_a}.{field}" to'
        f' "{table_b}.{back_reference}" must use the same model type'
        f" back-referenced."
    )

ormdantic.errors.MustUnionForeignKeyError

MustUnionForeignKeyError(
    table_a, table_b, field, model_b, pk_type
)

Bases: ConfigurationError

Raised when a relation field doesn't allow for just foreign key.

Source code in ormdantic/errors.py
def __init__(
    self,
    table_a: str,
    table_b: str,
    field: str,
    model_b: Type,  # type: ignore
    pk_type: Type,  # type: ignore
) -> None:
    super().__init__(
        f'Relation defined on "{table_a}.{field}" to "{table_b}" must be a union'
        f' type of "Model | model_pk_type" e.g. "{model_b.__name__} | {pk_type}"'
    )

ormdantic.errors.TypeConversionError

TypeConversionError(type)

Bases: ConfigurationError

Raised when a Python type fails to convert to SQL.

Source code in ormdantic/errors.py
def __init__(self, type: Type) -> None:  # type: ignore
    super().__init__(f"Type {type} is not supported by Ormdantic.")