Skip to content

Exceptions

All errors inherit from TinyStoreError:

TinyStoreError
├── IntegrityError
│   ├── UniqueConstraintError
│   ├── ForeignKeyError
│   └── StaleDataError          # optimistic-concurrency conflict
├── DoesNotExist
├── MultipleObjectsReturned
├── LockTimeoutError
├── TransactionError
├── SchemaError
├── RelationshipError
├── QueryError                  # incompatible-type comparisons, bad expressions
└── StorageError

Catch the specific ones you care about:

from tinystore import DoesNotExist, UniqueConstraintError

try:
    db.get(User, 999)
except DoesNotExist:
    ...

exceptions

Exception hierarchy for TinyStore.

All errors raised by TinyStore derive from :class:TinyStoreError, so callers can catch any database failure with a single except clause.

TinyStoreError

Bases: Exception

Base class for every TinyStore error.

IntegrityError

Bases: TinyStoreError

A data-integrity constraint was violated.

UniqueConstraintError

UniqueConstraintError(
    table: str, field: str, value: object
)

Bases: IntegrityError

A unique constraint would be violated by this write.

ForeignKeyError

Bases: IntegrityError

A foreign-key reference is invalid or would orphan a row.

StaleDataError

StaleDataError(table: str, pk: object)

Bases: IntegrityError

The row was modified by another writer since it was loaded (optimistic concurrency).

DoesNotExist

DoesNotExist(message: str = 'Object does not exist')

Bases: TinyStoreError

Exactly one row was expected but none was found.

MultipleObjectsReturned

MultipleObjectsReturned(
    message: str = "Multiple objects returned; expected one",
)

Bases: TinyStoreError

Exactly one row was expected but several matched.

LockTimeoutError

Bases: TinyStoreError

The lock could not be acquired within the configured timeout.

TransactionError

Bases: TinyStoreError

A transaction was used incorrectly (e.g. nested transactions).

SchemaError

Bases: TinyStoreError

The on-disk schema is missing, incompatible, or corrupt.

QueryError

Bases: TinyStoreError

A query expression is invalid (e.g. incompatible-type comparison).

RelationshipError

Bases: TinyStoreError

A relationship could not be resolved (unknown name, ambiguous target, etc.).

StorageError

Bases: TinyStoreError

The underlying storage layer reported a failure (I/O, corruption).