Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stufisher committed Jul 26, 2022
1 parent d29b941 commit 55076cf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyispyb/app/extensions/options/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging

from sqlalchemy import exc
from starlette.types import ASGIApp

from ispyb import models
Expand Down Expand Up @@ -63,15 +64,23 @@ def update_options(options: Options) -> Options:
try:
# Requires unique constraint to be lifted on `username` to enable storing more than
# just online stats
adminComment = ""
if not isinstance(option_value, dict) and not isinstance(
option_value, list
):
adminComment = f" to `{str(option_value)[:80]}`"

adminActivity = models.AdminActivity(
username=g.username,
action="db_options",
comments=f"changed `{option_key}` to `{option_value}`",
comments=f"changed `{option_key}`{adminComment}",
dateTime=datetime.now(),
)
db.session.add(adminActivity)
db.session.commit()
except Exception:
db.session.flush()
except exc.SQLAlchemyError:
db.session.rollback()
logger.exception("Could not log option change")

return options

0 comments on commit 55076cf

Please sign in to comment.