-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
standardize async dbapi exceptions with access pattern #8047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
makes sense. this would also work for sync driver, only "dbapi_expection" / "driver_exception" would point to the same object |
if someone wants to work on this sooner, it can be 2.0, but for now not an urgent need here |
This would be great. Currently in order to catch nowait lock errors from asyncpg I am doing string search for "LockNotAvailable" in the error message. Would much prefer to have access to the actual asyncpg exception. |
looking forward to get the origin exception as well |
Is pgcode an int code? |
nope, but looking at the |
I believe I'm running into this issue. I'm running SQLAlchemy 2.0 on top of
I think https://docs.sqlalchemy.org/en/20/core/exceptions.html#sqlalchemy.exc.DBAPIError makes an attempt at explaining this, but unfortunately that explanation went completely past my head. SQLAlchemy's |
except ProgrammingError as e:
if e.orig.pgcode == UndefinedTableError.sqlstate: hmmm, still string matching but a bit better workaround :) |
That was done to respect the pep249 exception hierarchy. The original exception is the cause of the custom pep249 excenption, since that's raised using |
Discussed in #8023
I think we should try to hit this in terms of all the async dialects all of which have to do what we are doing here, which would be that we make a common mixin / base for all the async-adapted DBAPIs. for asyncpg it would be used here:
sqlalchemy/lib/sqlalchemy/dialects/postgresql/asyncpg.py
Lines 760 to 761 in 19f0566
that way people can look at
EmulatedDBAPIException
to see the fields, which would be like:that looks kind of boring so we can also add an accessor on
sqlalchemy/lib/sqlalchemy/exc.py
Line 525 in 19f0566
that way someone that knows asyncpg can receive the top level SQLAlchemy DBAPIException and just refer to .driver_exception to get all the asyncpg fields.
The text was updated successfully, but these errors were encountered: