> 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
wrote:
>
> Personally, I would handle the check like this:
>
> ERRORS_UNDEFINED_TABLE = (psycopg2.errors.UndefinedTable, )
>
>
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
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
Rather than looking at the string representation, you could inspect
the "orig" attribute of the SQLAlchemy exception:
https://docs.sqlalchemy.org/en/13/core/exceptions.html#sqlalchemy.exc.DBAPIError
Simon
On Wed, Dec 4, 2019 at 5:52 PM Zsolt Ero wrote:
>
> My best idea so far is
>
> if
My best idea so far is
if 'psycopg2.errors.UndefinedTable' in str(err)
Just to note, I'm looking especially for psycopg2.errors.UndefinedTable,
I'm not using any other DB.
On Wednesday, 4 December 2019 18:37:02 UTC+1, Zsolt Ero wrote:
>
> Hi,
>
> I'm looking for a way to check for a table's