title: sqlalchemy.exc DataError Example Code
category: page
slug: sqlalchemy-exc-dataerror-examples
sortorder: 500031035
toc: False
sidebartitle: sqlalchemy.exc DataError
meta: Example code for understanding how to use the DataError class from the sqlalchemy.exc module of the SQLAlchemy project.
`DataError` is a class within the `sqlalchemy.exc` module of the SQLAlchemy project.
ArgumentError,
DatabaseError,
IntegrityError,
InvalidRequestError,
NoInspectionAvailable,
NoSuchTableError,
OperationalError,
ProgrammingError,
and UnsupportedCompilationError
are several other callables with code examples from the same `sqlalchemy.exc` package.
## Example 1 from sqlalchemy-utils
[sqlalchemy-utils](https://github.com/kvesteri/sqlalchemy-utils)
([project documentation](https://sqlalchemy-utils.readthedocs.io/en/latest/)
and
[PyPI package information](https://pypi.org/project/SQLAlchemy-Utils/))
is a code library with various helper functions and new data types
that make it easier to use [SQLAlchemy](/sqlalchemy.html) when building
projects that involve more specific storage requirements such as
[currency](https://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html#module-sqlalchemy_utils.types.currency).
The wide array of
[data types](https://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html)
includes [ranged values](https://sqlalchemy-utils.readthedocs.io/en/latest/range_data_types.html)
and [aggregated attributes](https://sqlalchemy-utils.readthedocs.io/en/latest/aggregates.html).
[**sqlalchemy-utils / sqlalchemy_utils / asserts.py**](https://github.com/kvesteri/sqlalchemy-utils/blob/master/sqlalchemy_utils/./asserts.py)
```python
# asserts.py
from decimal import Decimal
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ARRAY
~~from sqlalchemy.exc import DataError, IntegrityError
def _update_field(obj, field, value):
session = sa.orm.object_session(obj)
column = sa.inspect(obj.__class__).columns[field]
query = column.table.update().values(**{column.key: value})
session.execute(query)
session.flush()
def _expect_successful_update(obj, field, value, reraise_exc):
try:
_update_field(obj, field, value)
except (reraise_exc) as e:
session = sa.orm.object_session(obj)
session.rollback()
assert False, str(e)
def _expect_failing_update(obj, field, value, expected_exc):
try:
_update_field(obj, field, value)
except expected_exc:
pass
## ... source file continues with no further DataError examples...
```