From 9eedb9bf65f31bfb74d02adc8ffd46effb8ec163 Mon Sep 17 00:00:00 2001 From: Allen Short Date: Wed, 21 Mar 2018 20:38:48 +0000 Subject: [PATCH] properly rollback failed db commits --- redash/handlers/dashboards.py | 2 ++ redash/handlers/data_sources.py | 2 ++ redash/handlers/users.py | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/redash/handlers/dashboards.py b/redash/handlers/dashboards.py index 30ab41f801..499aff3445 100644 --- a/redash/handlers/dashboards.py +++ b/redash/handlers/dashboards.py @@ -159,8 +159,10 @@ def post(self, dashboard_slug): try: models.db.session.commit() except StaleDataError: + models.db.session.rollback() abort(409) except IntegrityError: + models.db.session.rollback() abort(400) result = dashboard.to_dict(with_widgets=True, user=self.current_user) diff --git a/redash/handlers/data_sources.py b/redash/handlers/data_sources.py index b1ba4739b2..ef894f10af 100644 --- a/redash/handlers/data_sources.py +++ b/redash/handlers/data_sources.py @@ -54,6 +54,7 @@ def post(self, data_source_id): try: models.db.session.commit() except IntegrityError as e: + models.db.session.rollback() if req['name'] in e.message: abort(400, message="Data source with the name {} already exists.".format(req['name'])) @@ -127,6 +128,7 @@ def post(self): models.db.session.commit() except IntegrityError as e: + models.db.session.rollback() if req['name'] in e.message: abort(400, message="Data source with the name {} already exists.".format(req['name'])) diff --git a/redash/handlers/users.py b/redash/handlers/users.py index 65ee9e8989..404bd0f251 100644 --- a/redash/handlers/users.py +++ b/redash/handlers/users.py @@ -42,6 +42,7 @@ def post(self): models.db.session.add(user) models.db.session.commit() except IntegrityError as e: + models.db.session.rollback() if "email" in e.message: abort(400, message='Email already taken.') @@ -128,7 +129,7 @@ def post(self, user_id): message = "Email already taken." else: message = "Error updating record" - + models.db.session.rollback() abort(400, message=message) self.record_event({