From 1a65372b99e1b14aa52154bf556e5662e445024b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 16 2015 15:45:32 +0000 Subject: Some more catch in case we cannot communicate right with the DB --- diff --git a/progit/ui/fork.py b/progit/ui/fork.py index 2cf068f..86ebfb1 100644 --- a/progit/ui/fork.py +++ b/progit/ui/fork.py @@ -138,7 +138,14 @@ def request_pull(repo, requestid, username=None): request.commit_start = first_commit.oid.hex request.commit_stop = diff_commits[0].oid.hex SESSION.add(request) - SESSION.commit() + try: + SESSION.commit() + except SQLAlchemyError as err: + SESSION.rollback() + APP.logger.exception(err) + flask.flash( + 'Could not update this pull-request in the database', + 'error') if diff_commits: first_commit = repo_obj[diff_commits[-1].oid.hex] @@ -287,6 +294,7 @@ def pull_request_add_comment(repo, requestid, commit, filename, row, flask.flash(message) except SQLAlchemyError, err: # pragma: no cover SESSION.rollback() + APP.logger.exception(err) flask.flash(str(err), 'error') return flask.redirect(flask.url_for( @@ -389,7 +397,12 @@ def merge_request_pull(repo, requestid, username=None): (merge is None and mergecode & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE)): flask.flash('Nothing to do, changes were already merged', 'error') progit.lib.close_pull_request(SESSION, request) - SESSION.commit() + try: + SESSION.commit() + except SQLAlchemyError as err: + SESSION.rollback() + APP.logger.exception(err) + flask.flash('Could not close this pull-request', 'error') return flask.redirect(error_output) elif ((merge is not None and merge.is_fastforward) or @@ -430,7 +443,14 @@ def merge_request_pull(repo, requestid, username=None): # Update status progit.lib.close_pull_request(SESSION, request, flask.g.fas_user) - SESSION.commit() + try: + SESSION.commit() + except SQLAlchemyError as err: + SESSION.rollback() + APP.logger.exception(err) + flask.flash( + 'Could not update this pull-request in the database', + 'error') shutil.rmtree(newpath) return flask.redirect(flask.url_for('view_repo', repo=repo.name))