From 25a82a20279703f04b9e2c11ed5872b76cf53498 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Sat, 23 Aug 2014 16:52:57 +0530 Subject: [PATCH] Fix: Catch DBApi error so that timeout errors don't lock up the software. --- brewman/models/validation_exception.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/brewman/models/validation_exception.py b/brewman/models/validation_exception.py index 29607b9f..2a316dd9 100644 --- a/brewman/models/validation_exception.py +++ b/brewman/models/validation_exception.py @@ -1,7 +1,8 @@ from pyramid.response import Response -from sqlalchemy.exc import OperationalError, IntegrityError +from sqlalchemy.exc import OperationalError, IntegrityError, DBAPIError import transaction + class ValidationError(Exception): def __init__(self, message, Errors=None): self.message = message @@ -10,6 +11,7 @@ class ValidationError(Exception): # Now for your custom code... self.Errors = Errors + def __str__(self): return self.message @@ -18,9 +20,11 @@ def TryCatchFunction(f): def _decorator(self, *args, **kwargs): try: return f(self, *args, **kwargs) - except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError) as ex: + except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError, + DBAPIError) as ex: transaction.abort() response = Response("Failed validation: {0}".format(str(ex))) response.status_int = 500 return response + return _decorator