Skip to content

Commit

Permalink
return exceptions on Execute commands for postgresql (asyncpg driver)
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Oct 24, 2024
1 parent e422c87 commit 4cbdb53
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
62 changes: 56 additions & 6 deletions asyncdb/drivers/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
UndefinedColumnError,
UndefinedTableError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError,
QueryCanceledError
)
from asyncpg.pgproto import pgproto
from ..exceptions import (
Expand Down Expand Up @@ -414,10 +417,25 @@ async def execute(self, sentence, *args):
"""
try:
return await self._pool.execute(sentence, *args)
except (
QueryCanceledError,
StatementError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError
) as err:
self._logger.warning(
f"AsyncPg: {err}"
)
raise
except InterfaceError as err:
raise ProviderError(f"Execute Interface Error: {err}") from err
raise ProviderError(
f"Execute Interface Error: {err}"
) from err
except Exception as err:
raise ProviderError(f"Execute Error: {err}") from err
raise ProviderError(
f"Execute Error: {err}"
) from err


class pgCursor(SQLCursor):
Expand Down Expand Up @@ -795,8 +813,24 @@ async def execute(self, sentence: Any, *args, **kwargs) -> Optional[Any]:
await self.valid_operation(sentence)
try:
self._result = await self._connection.execute(sentence, *args, **kwargs)
except (InvalidSQLStatementNameError, PostgresSyntaxError, UndefinedColumnError, UndefinedTableError) as err:
error = f"Sentence Error: {err}"
except (
QueryCanceledError,
StatementError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError
) as err:
self._logger.warning(
f"AsyncPg: {err}"
)
raise
except (
InvalidSQLStatementNameError,
PostgresSyntaxError,
UndefinedColumnError,
UndefinedTableError
) as err:
error = err
except DuplicateTableError as err:
error = f"Duplicated table: {err}"
except PostgresError as err:
Expand All @@ -813,10 +847,26 @@ async def execute_many(self, sentence: str, *args):
await self.valid_operation(sentence)
try:
self._result = await self._connection.executemany(sentence, *args)
except (
QueryCanceledError,
StatementError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError
) as err:
self._logger.warning(
f"AsyncPg: {err}"
)
raise
except InterfaceWarning as err:
error = f"Interface Warning: {err}"
except (InvalidSQLStatementNameError, PostgresSyntaxError, UndefinedColumnError, UndefinedTableError) as err:
error = f"Sentence Error: {err}"
except (
InvalidSQLStatementNameError,
PostgresSyntaxError,
UndefinedColumnError,
UndefinedTableError
) as err:
error = err
except DuplicateTableError as err:
error = f"Duplicated table: {err}"
except PostgresError as err:
Expand Down
2 changes: 1 addition & 1 deletion asyncdb/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__title__ = "asyncdb"
__description__ = "Library for Asynchronous data source connections \
Collection of asyncio drivers."
__version__ = "2.9.3"
__version__ = "2.9.4"
__author__ = "Jesus Lara"
__author_email__ = "[email protected]"
__license__ = "BSD"

0 comments on commit 4cbdb53

Please sign in to comment.