Exceptions

exception sheraf.exceptions.ConnectionAlreadyOpened[source]

Bases: SherafException

Raised when user tries to open an connection when a connection is already opened.

>>> with sheraf.connection():
...     with sheraf.connection():
...         do_amazing_stuff()
Traceback (most recent call last):
    ...
sheraf.exceptions.ConnectionAlreadyOpened: First connection was <Connection at ...> on ... at line ...
exception sheraf.exceptions.EmptyQuerySetUnpackException(message=None, queryset=None)[source]

Bases: QuerySetUnpackException

Raised when calling get() on QuerySet containing 0 element.

>>> # Fails with zero value
... with sheraf.connection():
...     Cowboy.filter(name="unknown cowboy").get()
Traceback (most recent call last):
...
sheraf.exceptions.EmptyQuerySetUnpackException: Trying to unpack an empty QuerySet
exception sheraf.exceptions.IndexationWarning[source]

Bases: UserWarning

This warning is emitted when you edit or create a model instance which has an outdated indexation table.

exception sheraf.exceptions.InvalidFilterException[source]

Bases: SherafException

Raised when an invalid QuerySet filter has been called.

>>> class MyModel(sheraf.Model):
...    my_attribute = sheraf.SimpleAttribute()
...
>>> with sheraf.connection():
...    MyModel.filter(foobar=True)
Traceback (most recent call last):
    ...
sheraf.exceptions.InvalidFilterException: MyModel has no attribute foobar
exception sheraf.exceptions.InvalidIndexException[source]

Bases: SherafException

This exception is raised by read() and read_these() when a parameter is passed and is not a valid index.

>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     age = sheraf.IntegerAttribute().index()
...
>>> with sheraf.connection():
...     Cowboy.read(size=4)
Traceback (most recent call last):
...
sheraf.exceptions.InvalidIndexException: 'size' is not a valid index
exception sheraf.exceptions.InvalidOrderException[source]

Bases: SherafException

Raised when an invalid QuerySet order has been called.

>>> class MyModel(sheraf.Model):
...    table = "my_model"
...    my_attribute = sheraf.SimpleAttribute()
...
>>> with sheraf.connection():
...    MyModel.all().order(foobar=True)
Traceback (most recent call last):
    ...
sheraf.exceptions.InvalidOrderException: MyModel has no attribute foobar
>>> with sheraf.connection():
...    MyModel.all().order(my_attribute=sheraf.ASC) \
...                 .order(my_attribute=sheraf.DESC)  # Raises an InvalidOrderException
Traceback (most recent call last):
    ...
sheraf.exceptions.InvalidOrderException: Some order parameters appeared twice
exception sheraf.exceptions.ModelObjectNotFoundException(model_class, identifier, index_name=None)[source]

Bases: ObjectNotFoundException

Raised when trying to read an unexisting ModelObject.

Parameters:
  • model_class (sheraf.models.BaseModelMetaclass) – Model class of the unfound object

  • object_id (str) – Id of the unfound object

exception sheraf.exceptions.MultipleIndexException[source]

Bases: InvalidIndexException

This exception is raised by read() when a multiple index is passed as a positionnal argument.

>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.StringAttribute()
...     hobby = sheraf.StringAttribute().index()
...
>>> with sheraf.connection():
...     Cowboy.create(name="George", hobby="nice hats")
...     Cowboy.create(name="Peter", hobby="nice hats")
...     Cowboy.read(hobby="nice hats")
Traceback (most recent call last):
...
sheraf.exceptions.MultipleIndexException: 'hobby' is a multiple index and cannot be used with 'read'
exception sheraf.exceptions.NoDatabaseConnectionException[source]

Bases: SherafException

Raised when calling read() and there is no connection to the database specified by the attribute database_name.

exception sheraf.exceptions.NotConnectedException[source]

Bases: SherafException

Raised when trying to handle things in the database while not being connected.

>>> with sheraf.connection():
...     sheraf.attempt(do_amazing_stuff)  # produces amazing stuff
...
>>> sheraf.commit()
Traceback (most recent call last):
    ...
sheraf.exceptions.NotConnectedException
exception sheraf.exceptions.ObjectNotFoundException[source]

Bases: SherafException

Raised when trying to read an unexisting object.

exception sheraf.exceptions.PrimaryKeyException[source]

Bases: SherafException

This exception is raised when issues happens with index primary keys.

When creating a model with zero, or several primary indexes.

>>> class Horse(sheraf.AttributeModel):
...     name = sheraf.StringAttribute().index(primary=True)
...     breed = sheraf.StringAttribute().index(primary=True)
...
>>> class Cowboy(sheraf.Model):
...     name = sheraf.StringAttribute()
...     horses = sheraf.IndexedModelAttribute(Horse)
...
>>> with sheraf.connection():
...     george = Cowboy.create(name="George Abitbol")
...     george.horses.create(name="Jolly Jumper", breed="shetland")
Traceback (most recent call last):
...
sheraf.exceptions.PrimaryKeyException: "A model can have only one primary key. 'Horse' has 'name' and 'breed'"
exception sheraf.exceptions.QuerySetUnpackException(message=None, queryset=None)[source]

Bases: SherafException

exception sheraf.exceptions.SameNameForTableException[source]

Bases: SherafException

Raised when two models have the same “table” attribute.

>>> class FirstModel(sheraf.Model):
...     table = "first_model"
...
>>> class SecondModel(sheraf.Model):
...     table = "first_model"
Traceback (most recent call last):
    ...
sheraf.exceptions.SameNameForTableException: Table named 'first_model' used twice (FirstModel and SecondModel)
exception sheraf.exceptions.SherafException[source]

Bases: Exception

Main sheraf exception.

exception sheraf.exceptions.TooManyValuesSetUnpackException(message=None, queryset=None)[source]

Bases: QuerySetUnpackException

Raised when calling get() on QuerySet containing more than one element.

>>> # Fails with zero value
... with sheraf.connection():
...     Cowboy.filter(name="unknown cowboy").get()
Traceback (most recent call last):
...
sheraf.exceptions.EmptyQuerySetUnpackException: Trying to unpack a QuerySet with multiple elements
exception sheraf.exceptions.UniqueIndexException[source]

Bases: InvalidIndexException

This exception is raised when a value is set twice in an unique index.

>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.StringAttribute().index(unique=True)
...
>>> with sheraf.connection():
...     Cowboy.create(name="George Abitbol")
...     Cowboy.create(name="George Abitbol")
Traceback (most recent call last):
...
sheraf.exceptions.UniqueIndexException: The key 'George Abitbol' is already present in the index 'name'