Skip to content

Commit 3253415

Browse files
Merge pull request #471 from laughingman7743/fix_exception_alias
Fix exceptions alias
2 parents 7994cea + 373bff7 commit 3253415

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pyathena/sqlalchemy/base.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from sqlalchemy import exc, schema, types, util
2323
from sqlalchemy.engine import Engine, reflection
2424
from sqlalchemy.engine.default import DefaultDialect
25-
from sqlalchemy.exc import NoSuchTableError
2625
from sqlalchemy.sql.compiler import (
2726
ILLEGAL_INITIAL_CHARACTERS,
2827
DDLCompiler,
@@ -837,10 +836,10 @@ def _prepared_columns(
837836
or f"{table.name}.{column.name}" in conn_buckets
838837
):
839838
buckets.append(f"\t{self.preparer.format_column(column)}")
840-
except exc.CompileError as ce:
839+
except exc.CompileError as e:
841840
raise exc.CompileError(
842-
f"(in table '{table.description}', column '{column.name}'): {ce.args[0]}"
843-
) from ce
841+
f"(in table '{table.description}', column '{column.name}'): {e.args[0]}"
842+
) from e
844843
return columns, partitions, buckets
845844

846845
def visit_create_table(self, create: "CreateTable", **kwargs) -> str:
@@ -1020,8 +1019,8 @@ def _get_schemas(self, connection, **kw):
10201019
with raw_connection.driver_connection.cursor() as cursor: # type: ignore
10211020
try:
10221021
return cursor.list_databases(catalog)
1023-
except pyathena.error.OperationalError as exc:
1024-
cause = exc.__cause__
1022+
except pyathena.error.OperationalError as e:
1023+
cause = e.__cause__
10251024
if (
10261025
isinstance(cause, botocore.exceptions.ClientError)
10271026
and cause.response["Error"]["Code"] == "InvalidRequestException"
@@ -1036,13 +1035,13 @@ def _get_table(self, connection, table_name: str, schema: Optional[str] = None,
10361035
with raw_connection.driver_connection.cursor() as cursor: # type: ignore
10371036
try:
10381037
return cursor.get_table_metadata(table_name, schema_name=schema, logging_=False)
1039-
except pyathena.error.OperationalError as exc:
1040-
cause = exc.__cause__
1038+
except pyathena.error.OperationalError as e:
1039+
cause = e.__cause__
10411040
if (
10421041
isinstance(cause, botocore.exceptions.ClientError)
10431042
and cause.response["Error"]["Code"] == "MetadataException"
10441043
):
1045-
raise NoSuchTableError(table_name) from exc
1044+
raise exc.NoSuchTableError(table_name) from e
10461045
raise
10471046

10481047
@reflection.cache
@@ -1100,7 +1099,7 @@ def has_table(
11001099
try:
11011100
columns = self.get_columns(connection, table_name, schema)
11021101
return True if columns else False
1103-
except NoSuchTableError:
1102+
except exc.NoSuchTableError:
11041103
return False
11051104

11061105
@reflection.cache

0 commit comments

Comments
 (0)