]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Improve asyncpg exception hierarchy and asyncio hierarchies overall
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 20 Sep 2025 20:22:28 +0000 (16:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 23 Sep 2025 13:49:19 +0000 (09:49 -0400)
commit89a4174a8de0815605874a61a38639658aeb7eab
treed4fd53bfbd29cc22f18d6d5a8da944289ad7ad2b
parentf4f5b1931a9bcfe32570ae1458e85da9db2da6b4
Improve asyncpg exception hierarchy and asyncio hierarchies overall

The "emulated" exception hierarchies for the asyncio
drivers such as asyncpg, aiomysql, aioodbc, etc. have been standardized
on a common base :class:`.EmulatedDBAPIException`, which is now what's
available from the :attr:`.StatementException.orig` attribute on a
SQLAlchemy :class:`.DBAPIException` object.   Within :class:`.EmulatedDBAPIException`
and the subclasses in its hiearchy, the original driver-level exception is
also now avaliable via the :attr:`.EmulatedDBAPIException.orig` attribute,
and is also available from :class:`.DBAPIException` directly using the
:attr:`.DBAPIException.driver_exception` attribute.

Added additional emulated error classes for the subclasses of
``asyncpg.exception.IntegrityError`` including ``RestrictViolationError``,
``NotNullViolationError``, ``ForeignKeyViolationError``,
``UniqueViolationError`` ``CheckViolationError``,
``ExclusionViolationError``.  These exceptions are not directly thrown by
SQLAlchemy's asyncio emulation, however are available from the
newly added :attr:`.DBAPIException.driver_exception` attribute when a
:class:`.IntegrityError` is caught.

Fixes: #8047
Change-Id: I6a34e85b055265c087b0615f7c573be8582b3486
13 files changed:
doc/build/changelog/unreleased_21/8047.rst [new file with mode: 0644]
doc/build/core/internals.rst
lib/sqlalchemy/connectors/aioodbc.py
lib/sqlalchemy/connectors/asyncio.py
lib/sqlalchemy/dialects/mysql/aiomysql.py
lib/sqlalchemy/dialects/mysql/asyncmy.py
lib/sqlalchemy/dialects/oracle/oracledb.py
lib/sqlalchemy/dialects/postgresql/asyncpg.py
lib/sqlalchemy/dialects/postgresql/psycopg.py
lib/sqlalchemy/dialects/sqlite/aiosqlite.py
lib/sqlalchemy/exc.py
test/base/test_except.py
test/engine/test_execute.py