Skip to content

Commit

Permalink
fix: avoid crashing when analyzing sqlalchemy errors (#411)
Browse files Browse the repository at this point in the history
* fix: avoid crashing when analyzing sqlalchemy errors

* whoops
  • Loading branch information
matt-codecov authored Apr 24, 2024
1 parent 78b8c10 commit 5d85174
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,18 @@ def _analyse_error(self, exception: SQLAlchemyError, *args, **kwargs):
try:
import psycopg2

if isinstance(exception.orig, psycopg2.errors.DeadlockDetected):
if hasattr(exception, "orig") and isinstance(
exception.orig, psycopg2.errors.DeadlockDetected
):
log.exception(
"Deadlock while talking to database",
extra=dict(task_args=args, task_kwargs=kwargs),
exc_info=True,
)
return
elif isinstance(exception.orig, psycopg2.OperationalError):
elif hasattr(exception, "orig") and isinstance(
exception.orig, psycopg2.OperationalError
):
log.warning(
"Database seems to be unavailable",
extra=dict(task_args=args, task_kwargs=kwargs),
Expand Down

0 comments on commit 5d85174

Please sign in to comment.