> However I cannot catch for this error, I can only catch for "sqlalchemy.exc.ProgrammingError".
Why is that? James On Wed, Dec 4, 2019 at 6:03 PM Jonathan Vanasco <jonat...@findmeon.com> wrote: > > Personally, I would handle the check like this: > > ERRORS_UNDEFINED_TABLE = (psycopg2.errors.UndefinedTable, ) > > try: > res = conn.execute(stmt) > except sa.exc.ProgrammingError as err: > if isinstance(err.orig, ERRORS_UNDEFINED_TABLE): > print('Table does not exist') > raise > > > This would allow you to update the `ERRORS_UNDEFINED_TABLE` tuple in a > central place, and allow you to more easily catch this situation in other > databases if needed. I've used this technique in a few projects that are > built for postgres, but support mysql and use sqlite for some tests. > > > On Wednesday, December 4, 2019 at 5:52:15 PM UTC-5, Zsolt Ero wrote: >> >> Thanks. So is the following code correct for psycopg2 specific scenario? >> >> try: >> res = conn.execute(stmt) >> except sa.exc.ProgrammingError as err: >> if isinstance(err.orig, psycopg2.errors.UndefinedTable): >> print('Table does not exist') >> else: >> raise err >> > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/f936b2c1-bdcf-4372-8943-00a31615d70a%40googlegroups.com > <https://groups.google.com/d/msgid/sqlalchemy/f936b2c1-bdcf-4372-8943-00a31615d70a%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CALDF6i11hXvsywy0nAA86nSpet0h%3DGRDCZHxq6saEsyOdQA6cQ%40mail.gmail.com.