Skip to content

Commit

Permalink
Fix asynch error to comply with pep dbapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Chenzw committed Aug 28, 2024
1 parent 523559e commit a96bdf2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 1 addition & 3 deletions clickhouse_sqlalchemy/drivers/asynch/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import asynch

from sqlalchemy.sql.elements import TextClause
from sqlalchemy.pool import AsyncAdaptedQueuePool

Expand All @@ -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):
Expand Down
13 changes: 6 additions & 7 deletions clickhouse_sqlalchemy/drivers/asynch/connector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

import asynch
import asynch.errors
from sqlalchemy.engine.interfaces import AdaptedConnection
from sqlalchemy.util.concurrency import await_only

Expand Down Expand Up @@ -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',
Expand All @@ -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))
)


Expand Down

0 comments on commit a96bdf2

Please sign in to comment.