From a96bdf2addd1e494cffd6c5f846aee34760ae0fe Mon Sep 17 00:00:00 2001 From: Simon Chen <1020359403@qq.com> Date: Wed, 28 Aug 2024 07:08:47 +0000 Subject: [PATCH] Fix asynch error to comply with pep dbapi --- clickhouse_sqlalchemy/drivers/asynch/base.py | 4 +--- clickhouse_sqlalchemy/drivers/asynch/connector.py | 13 ++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/clickhouse_sqlalchemy/drivers/asynch/base.py b/clickhouse_sqlalchemy/drivers/asynch/base.py index 5a28ea6e..593a41f6 100644 --- a/clickhouse_sqlalchemy/drivers/asynch/base.py +++ b/clickhouse_sqlalchemy/drivers/asynch/base.py @@ -1,5 +1,3 @@ -import asynch - from sqlalchemy.sql.elements import TextClause from sqlalchemy.pool import AsyncAdaptedQueuePool @@ -25,7 +23,7 @@ class ClickHouseDialect_asynch(ClickHouseDialect_native): @classmethod def import_dbapi(cls): - return AsyncAdapt_asynch_dbapi(asynch) + return AsyncAdapt_asynch_dbapi() @classmethod def get_pool_class(cls, url): diff --git a/clickhouse_sqlalchemy/drivers/asynch/connector.py b/clickhouse_sqlalchemy/drivers/asynch/connector.py index c0be3d5c..b83a9095 100644 --- a/clickhouse_sqlalchemy/drivers/asynch/connector.py +++ b/clickhouse_sqlalchemy/drivers/asynch/connector.py @@ -1,5 +1,7 @@ import asyncio +import asynch +import asynch.errors from sqlalchemy.engine.interfaces import AdaptedConnection from sqlalchemy.util.concurrency import await_only @@ -109,15 +111,12 @@ def fetchall(self): class AsyncAdapt_asynch_dbapi: - def __init__(self, asynch): - self.asynch = asynch + def __init__(self): self.paramstyle = 'pyformat' self._init_dbapi_attributes() - class Error(Exception): - pass - def _init_dbapi_attributes(self): + self.Error = asynch.errors.ClickHouseException for name in ( 'ServerException', 'UnexpectedPacketFromServerError', @@ -141,12 +140,12 @@ def _init_dbapi_attributes(self): 'ProgrammingError', 'NotSupportedError', ): - setattr(self, name, getattr(self.asynch.errors, name)) + setattr(self, name, getattr(asynch.errors, name)) def connect(self, *args, **kwargs) -> 'AsyncAdapt_asynch_connection': return AsyncAdapt_asynch_connection( self, - await_only(self.asynch.connect(*args, **kwargs)) + await_only(asynch.connect(*args, **kwargs)) )