fictive.sqlalchemy.ext.errors package

Module contents

uniform interface for accessing the data in an sqlalchemy.exc.IntegrityError

class fictive.sqlalchemy.ext.errors.IntegrityErrorData(integrity_error: sqlalchemy.exc.IntegrityError)[source]

Bases: fictive.errors.ErrorData

Records information assocated with an sqlalchemy.exc.IntegrityError

E.g.:

>>> first = Model(value=1)
>>> session.add(first)
>>> second = Model(value=1)
>>> session.add(second)
>>> try:
...     session.commit()
>>> except sqlalchemy.exc.IntegrityError as integrity_error:
...     data = IntegrityErrorData(integrity_error)
>>> data.code
'UniqueViolation'
>>> assert data.fields
{'value': '1'}
>>> assert data.table
'model'
ERROR_CLASS

alias of sqlalchemy.exc.IntegrityError

__init__(integrity_error: sqlalchemy.exc.IntegrityError)[source]
Param

integrity_error: the sqlalchemy.exc.IntegrityError that contains a databasedriver error in its orig attribute

property code

use the class name as the default code

property fields

table columns and values that caused the error

property message

use the error itself as the default message

property table

the table that caused the error