aboutsummaryrefslogtreecommitdiff
path: root/src/web/controllers/abstract.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-10-28 23:58:21 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-10-28 23:58:21 +0200
commitba01f720cc1a7a2392bfda1d3eddda3375902a8d (patch)
treea0008a56159c95f2f3c86c58522db007c026c6f7 /src/web/controllers/abstract.py
parenta mess (diff)
downloadnewspipe-ba01f720cc1a7a2392bfda1d3eddda3375902a8d.tar.gz
newspipe-ba01f720cc1a7a2392bfda1d3eddda3375902a8d.tar.bz2
newspipe-ba01f720cc1a7a2392bfda1d3eddda3375902a8d.zip
Rollback if the last query fails.
Diffstat (limited to 'src/web/controllers/abstract.py')
-rw-r--r--src/web/controllers/abstract.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/web/controllers/abstract.py b/src/web/controllers/abstract.py
index 5cebd39e..7e167722 100644
--- a/src/web/controllers/abstract.py
+++ b/src/web/controllers/abstract.py
@@ -94,6 +94,7 @@ class AbstractController:
try:
db.session.commit()
except Exception as e:
+ db.session.rollback()
logger.exception(str(e))
return obj
@@ -103,13 +104,19 @@ class AbstractController:
def update(self, filters, attrs):
assert attrs, "attributes to update must not be empty"
result = self._get(**filters).update(attrs, synchronize_session=False)
- db.session.commit()
+ try:
+ db.session.commit()
+ except Exception as e:
+ db.session.rollback()
return result
def delete(self, obj_id):
obj = self.get(id=obj_id)
db.session.delete(obj)
- db.session.commit()
+ try:
+ db.session.commit()
+ except Exception as e:
+ db.session.rollback()
return obj
def _has_right_on(self, obj):
bgstack15