Skip to content

Commit

Permalink
Rollback transaction when session query throws exception
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Brain <[email protected]>
  • Loading branch information
ABrain7710 committed Apr 27, 2024
1 parent 2474c56 commit a6253f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion augur/application/db/models/augur_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion augur/application/db/models/augur_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a6253f0

Please sign in to comment.