Skip to content

Commit

Permalink
Merge pull request #1225 from phenobarbital/new-drivers
Browse files Browse the repository at this point in the history
upgrading libraries for work on new drivers
  • Loading branch information
phenobarbital authored Aug 30, 2024
2 parents de4aa80 + 021a0c2 commit dc1d6bb
Show file tree
Hide file tree
Showing 32 changed files with 105 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@ env/
*.c
asyncdb/utils/types.cpp
asyncdb/exceptions/exceptions.c
docs/nyc_taxi/*
7 changes: 4 additions & 3 deletions asyncdb/drivers/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,10 @@ def _decoder(value):
if self._pool and not self._connection:
self._connection = await self._pool.pool().acquire()
else:
loop = self._loop
if not loop:
loop = asyncio.get_running_loop()
# try:
# loop = self._loop or asyncio.get_running_loop()
# except RuntimeError:
# loop = asyncio.get_event_loop()
self._connection = await asyncpg.connect(
dsn=self._dsn,
timeout=self._timeout,
Expand Down
43 changes: 28 additions & 15 deletions asyncdb/exceptions/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import asyncio
import logging

def handle_done_tasks(task: asyncio.Task, logger: logging.Logger, *args: tuple[Any, ...]) -> None:

def handle_done_tasks(
task: asyncio.Task,
logger: logging.Logger,
*args: tuple[Any, ...]
) -> None:
try:
return task.result()
except asyncio.CancelledError:
Expand Down Expand Up @@ -48,17 +53,25 @@ def default_exception_handler(loop: asyncio.AbstractEventLoop, context):
# Call the default exception handler
loop.default_exception_handler(context)

if exception:
logging.error(f"AsyncDB: Caught exception: {exception}")
if not isinstance(exception, asyncio.CancelledError):
try:
exc_name = type(exception).__name__
logging.error(f"{exc_name}: *{msg}* over task {task}")
except Exception as ex:
logging.exception("Handler Error", exc_info=True)
raise RuntimeError(f"Handler Error: {ex}") from ex
else:
logging.error(f"AsyncDB: Caught an error: {context}")
if task:
logging.exception(f"Exception raised by Task {task}, Error: {msg}")
raise RuntimeError(f"{msg}: task: {task}")
if not exception and not msg:
logging.error(
"AsyncDB: Caught an error with no exception or message in context."
)
raise RuntimeError(f"Unknown error: task: {task}")

if isinstance(exception, asyncio.CancelledError):
return

try:
if exception:
exc_name = type(exception).__name__
task_info = f"Task {task}" if task else "Unknown task"
logging.error(f"{exc_name}: *{msg}* over {task_info}")
else:
logging.error(f"AsyncDB: Caught an error: {context}")
if task:
logging.exception(f"Exception raised by Task {task}, Error: {msg}")
raise RuntimeError(f"{msg}: task: {task}")
except Exception as ex:
logging.exception("Handler Error", exc_info=True)
raise RuntimeError(f"Handler Error: {ex}") from ex
Loading

0 comments on commit dc1d6bb

Please sign in to comment.