Skip to content

Commit

Permalink
Merge pull request #1321 from phenobarbital/new-drivers
Browse files Browse the repository at this point in the history
added exceptions to Copy into table method for asyncpg
  • Loading branch information
phenobarbital authored Oct 24, 2024
2 parents 17f48c0 + f55b899 commit 9ae076c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
43 changes: 38 additions & 5 deletions asyncdb/drivers/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,17 @@ async def copy_from_table(self, table="", schema="public", output=None, file_typ
output=output,
)
return result
except (
QueryCanceledError,
StatementError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError
) as err:
self._logger.warning(
f"AsyncPg Copy From Table: {err}"
)
raise
except UndefinedTableError as ex:
raise StatementError(f"Error on Copy, Table {table }doesn't exists: {ex}") from ex
except (InvalidSQLStatementNameError, PostgresSyntaxError, UndefinedColumnError) as ex:
Expand Down Expand Up @@ -1012,10 +1023,23 @@ async def copy_to_table(self, table="", schema="public", source=None, file_type=
source=source,
)
return result
except (
QueryCanceledError,
StatementError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError
) as err:
self._logger.warning(
f"AsyncPg Copy To Table: {err}"
)
raise
except UndefinedTableError as ex:
raise StatementError(f"Error on Copy to Table {table }doesn't exists: {ex}") from ex
raise StatementError(
f"Error on Copy to Table {table } doesn't exists: {ex}") from ex
except (InvalidSQLStatementNameError, PostgresSyntaxError, UndefinedColumnError) as ex:
raise StatementError(f"Error on Copy, Invalid Statement Error: {ex}") from ex
raise StatementError(
f"Error on Copy, Invalid Statement Error: {ex}") from ex
except Exception as ex:
raise DriverError(f"Error on Copy to Table {ex}") from ex

Expand All @@ -1035,12 +1059,21 @@ async def copy_into_table(self, table="", schema="public", source=None, columns=
table_name=table, schema_name=schema, columns=columns, records=source
)
return result
except (
QueryCanceledError,
StatementError,
UniqueViolationError,
ForeignKeyViolationError,
NotNullViolationError
) as err:
self._logger.warning(
f"AsyncPg Copy Into Table: {err}"
)
raise
except UndefinedTableError as ex:
raise StatementError(f"Error on Copy to Table {table }doesn't exists: {ex}") from ex
raise StatementError(f"Error on Copy to Table {table } doesn't exists: {ex}") from ex
except (InvalidSQLStatementNameError, PostgresSyntaxError, UndefinedColumnError) as ex:
raise StatementError(f"Error on Copy, Invalid Statement Error: {ex}") from ex
except UniqueViolationError as ex:
raise StatementError(f"Error on Copy, Constraint Violated: {ex}") from ex
except InterfaceError as ex:
raise DriverError(f"Error on Copy into Table Function: {ex}") from ex
except (RuntimeError, PostgresError) as ex:
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.4"
__version__ = "2.9.5"
__author__ = "Jesus Lara"
__author_email__ = "[email protected]"
__license__ = "BSD"

0 comments on commit 9ae076c

Please sign in to comment.