Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to database exception handling #410

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions _infra/helm/party/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 2.4.35
version: 2.4.36

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 2.4.35
appVersion: 2.4.36
16 changes: 11 additions & 5 deletions ras_party/support/session_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import structlog
from flask import current_app
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.exc import OperationalError, SQLAlchemyError

logger = structlog.wrap_logger(logging.getLogger(__name__))

Expand Down Expand Up @@ -31,8 +31,11 @@ def handle_query_only_session(f, args, kwargs):
try:
result = f(*args, session=session, **kwargs)
return result
except SQLAlchemyError:
logger.error("Something went wrong accessing database", exc_info=True)
except SQLAlchemyError as exc:
if isinstance(exc, OperationalError):
logger.error("Connection to database interrupted", exc_info=True)
else:
logger.error(f"Something went wrong accessing database due to {exc.__class__.__name__}", exc_info=True)
raise
finally:
current_app.db.session.remove()
Expand All @@ -44,8 +47,11 @@ def handle_quiet_session(f, args, kwargs):
result = f(*args, session=session, **kwargs)
session.commit()
return result
except SQLAlchemyError:
logger.error("Something went wrong accessing database", exc_info=True)
except SQLAlchemyError as exc:
if isinstance(exc, OperationalError):
logger.error("Connection to database interrupted", exc_info=True)
else:
logger.error(f"Something went wrong accessing database due to {exc.__class__.__name__}", exc_info=True)
session.rollback()
raise
finally:
Expand Down
Loading