Skip to content

# odmantic.exceptions

Bases: `Exception`

Base Exception raised by the engine while operating with the database.

Source code in `odmantic/exceptions.py`

    14
    15
    16
    17
    18
    19

    class BaseEngineException(Exception, metaclass=ABCMeta):
        """Base Exception raised by the engine while operating with the database."""

        def __init__(self, message: str, model: Type["Model"]):
            self.model: Type["Model"] = model
            super().__init__(message)

Bases: `BaseEngineException`

The targetted document has not been found by the engine.

Attributes:

Name | Type | Description
--- | --- | ---
`instance` | `Model` | the instance that has not been found

Source code in `odmantic/exceptions.py`

    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35

    class DocumentNotFoundError(BaseEngineException):
        """The targetted document has not been found by the engine.

        Attributes:
          instance: the instance that has not been found
        """

        def __init__(self, instance: "Model"):
            self.instance: "Model" = instance
            super().__init__(
                f"Document not found for : {type(instance).__name__}. "
                f"Instance: {self.instance}",
                type(instance),
            )

Bases: `ValueError`

Unable to parse the document into an instance.

Inherits from the `ValidationError` defined by Pydantic.

Attributes:

Name | Type | Description
--- | --- | ---
`model` | `Union[Type[Model], Type[EmbeddedModel]]` | model which could not be instanciated

Source code in `odmantic/exceptions.py`

     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120

    class DocumentParsingError(ValueError):
        """Unable to parse the document into an instance.

        Inherits from the `ValidationError` defined by Pydantic.

        Attributes:
          model (Union[Type[Model],Type[EmbeddedModel]]): model which could not be
            instanciated
        """

        def __init__(
            self,
            errors: ErrorList,
            model: Type["_BaseODMModel"],
        ):
            self.model = model
            self.inner = ValidationError.from_exception_data(
                title=self.model.__name__,
                line_errors=errors,
            )

        def __str__(self) -> str:
            return str(self.inner)

        def __repr__(self) -> str:
            return repr(self.inner)

Bases: `BaseEngineException`

The targetted document is duplicated according to a unique index.

Attributes:

Name | Type | Description
--- | --- | ---
`instance` | `Model` | the instance that has not been found
`driver_error` |  | the original driver error

Source code in `odmantic/exceptions.py`

    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56

    class DuplicateKeyError(BaseEngineException):
        """The targetted document is duplicated according to a unique index.

        Attributes:
          instance: the instance that has not been found
          driver_error: the original driver error
        """

        def __init__(
            self, instance: "Model", driver_error: pymongo.errors.DuplicateKeyError
        ):
            self.instance: "Model" = instance
            self.driver_error = driver_error
            super().__init__(
                f"Duplicate key error for: {type(instance).__name__}. "
                f"Instance: {self.instance} "
                f"Driver error: {self.driver_error}",
                type(instance),
            )