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

Added rollback to when there are db errors #227

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/esportsbot/db_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def list(db_model, **args):
query = session.query(db_model).filter_by(**args).all()
return query
except Exception as err:
session.rollback()
raise Exception(f"Error occurred when using list - {err}")

@staticmethod
Expand All @@ -62,6 +63,7 @@ def get(db_model, **args):
query = session.query(db_model).filter_by(**args).all()
return query[0] if query != [] else query
except Exception as err:
session.rollback()
raise Exception(f"Error occurred when using get - {err}")

@staticmethod
Expand All @@ -76,6 +78,7 @@ def update(model):
session.add(model)
session.commit()
except Exception as err:
session.rollback()
raise Exception(f"Error occurred when using update - {err}")

@staticmethod
Expand All @@ -90,6 +93,7 @@ def delete(model):
session.delete(model)
session.commit()
except Exception as err:
session.rollback()
raise Exception(f"Error occurred when using delete - {err}")

@staticmethod
Expand All @@ -104,4 +108,5 @@ def create(model):
session.add(model)
session.commit()
except Exception as err:
session.rollback()
raise Exception(f"Error occurred when using create - {err}")