SQLAlchemy does not catch postgresql.exceptions.UniqueError

Issue #3421 resolved
András Tim created an issue

SQLAlchemy does not catch postgresql.exceptions.UniqueError. In normal case SQLAlchemy catches all exceptions and make standardized exceptions.

This exception should be an sqlalchemy.exc.IntegrityError.

Comments (4)

  1. Mike Bayer repo owner

    the reason this occurs is because py-postgresql is using a hack for their IntegrityError, by re-using an entirely different exception class with a different name:

    >>> from postgresql.driver import dbapi20
    >>> dbapi20.IntegrityError
    <class 'postgresql.exceptions.ICVError'>
    

    we'd have to rewrite our entire exception wrapping system to support this. py-postgresql hasn't had a release in three years and is a dead project; the psycopg2 project supports Python 3 and is an industry-wide standard for Python postgresql access. Can't you just use that ?

  2. Mike Bayer repo owner
    • Added support for the case of the misbehaving DBAPI that has pep-249 exception names linked to exception classes of an entirely different name, preventing SQLAlchemy's own exception wrapping from wrapping the error appropriately. The SQLAlchemy dialect in use needs to implement a new accessor :attr:.DefaultDialect.dbapi_exception_translation_map to support this feature; this is implemented now for the py-postgresql dialect. fixes #3421

    → <<cset d178707ecaeb>>

  3. Log in to comment