summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/asyncpg.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-05 14:41:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-05 20:13:01 -0400
commitd01790ebe0b425bf79c4decf24011d0d6234944d (patch)
treef9e4267e46239671f123743c21672141d56c6626 /lib/sqlalchemy/dialects/postgresql/asyncpg.py
parent165c3a65dcb1ba3f42ecf2b5da7c298bdc259f9b (diff)
downloadsqlalchemy-d01790ebe0b425bf79c4decf24011d0d6234944d.tar.gz
Add pgcode / sqlstate for asyncpg error message
Added accessors ``.sqlstate`` and synonym ``.pgcode`` to the ``.orig`` attribute of the SQLAlchemy exception class raised by the asyncpg DBAPI adapter, that is, the intermediary exception object that wraps on top of that raised by the asyncpg library itself, but below the level of the SQLAlchemy dialect. Fixes: #6199 Change-Id: Ie0f1ffaaff47c7a50dd1fbccdbe588cdc5322b70
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/asyncpg.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/asyncpg.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
index 8cd5bee41..4a191cd28 100644
--- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py
+++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
@@ -646,6 +646,9 @@ class AsyncAdapt_asyncpg_connection:
translated_error = exception_mapping[super_](
"%s: %s" % (type(error), error)
)
+ translated_error.pgcode = (
+ translated_error.sqlstate
+ ) = getattr(error, "sqlstate", None)
raise translated_error from error
else:
raise error