Skip to content

Errors Handling

ormdantic.handler.errors.ConfigurationError

ConfigurationError(msg)

Bases: Exception

Raised for mal-configured database models or schemas.

PARAMETER DESCRIPTION
msg

TYPE: str

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

ormdantic.handler.errors.UndefinedBackReferenceError

UndefinedBackReferenceError(table_a, table_b, field)

Bases: ConfigurationError

Raised when a back reference is missing from a table.

PARAMETER DESCRIPTION
table_a

TYPE: str

table_b

TYPE: str

field

TYPE: str

Source code in ormdantic/handler/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.handler.errors.MismatchingBackReferenceError

MismatchingBackReferenceError(table_a, table_b, field, back_reference)

Bases: ConfigurationError

Raised when a back reference is typed incorrectly.

PARAMETER DESCRIPTION
table_a

TYPE: str

table_b

TYPE: str

field

TYPE: str

back_reference

TYPE: str

Source code in ormdantic/handler/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.handler.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.

PARAMETER DESCRIPTION
table_a

TYPE: str

table_b

TYPE: str

field

TYPE: str

model_b

TYPE: Type

pk_type

TYPE: Type

Source code in ormdantic/handler/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.handler.errors.TypeConversionError

TypeConversionError(type)

Bases: ConfigurationError

Raised when a Python type fails to convert to SQL.

PARAMETER DESCRIPTION
type

TYPE: Type

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