From a6253f0b6978aa7ef05d0f835a236ed66aa3f0d2 Mon Sep 17 00:00:00 2001 From: Andrew Brain Date: Sat, 27 Apr 2024 16:12:40 -0500 Subject: [PATCH] Rollback transaction when session query throws exception Signed-off-by: Andrew Brain --- augur/application/db/models/augur_data.py | 8 +++++++- augur/application/db/models/augur_operations.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/augur/application/db/models/augur_data.py b/augur/application/db/models/augur_data.py index 606236df21..bdbdb8f8a6 100644 --- a/augur/application/db/models/augur_data.py +++ b/augur/application/db/models/augur_data.py @@ -878,7 +878,13 @@ class Repo(Base): @staticmethod def get_by_id(session, repo_id): - return session.query(Repo).filter(Repo.repo_id == repo_id).first() + try: + return session.query(Repo).filter(Repo.repo_id == repo_id).first() + except Exception as e: + session.rollback() + raise e + + @staticmethod def get_by_repo_git(session, repo_git): diff --git a/augur/application/db/models/augur_operations.py b/augur/application/db/models/augur_operations.py index 47f28b12f2..029444215e 100644 --- a/augur/application/db/models/augur_operations.py +++ b/augur/application/db/models/augur_operations.py @@ -329,6 +329,9 @@ def get_user(session, username: str): return user except NoResultFound: return None + except Exception as e: + session.rollback() + raise e @staticmethod def get_by_id(session, user_id: int): @@ -1073,7 +1076,13 @@ def __eq__(self, other): @staticmethod def get_by_id(session, client_id): - return session.query(ClientApplication).filter(ClientApplication.id == client_id).first() + + try: + return session.query(ClientApplication).filter(ClientApplication.id == client_id).first() + except Exception as e: + session.rollback() + raise e + class Subscription(Base): __tablename__ = "subscriptions"