Trying to catch database locked error

This commit is contained in:
Tanshu 2012-12-25 13:55:28 +05:30
parent f0e3ba19e8
commit 6b89a93bde
3 changed files with 5 additions and 3 deletions

View File

@ -1,4 +1,5 @@
from pyramid.response import Response
from sqlalchemy.exc import OperationalError
import transaction
class ValidationError(Exception):
@ -17,7 +18,7 @@ def TryCatchFunction(f):
def _decorator(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except (ValidationError, ValueError, KeyError, AttributeError, TypeError) as ex:
except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError) as ex:
transaction.abort()
response = Response("Failed validation: {0}".format(str(ex)))
response.status_int = 500

View File

@ -77,6 +77,7 @@ def check_delete_permissions(request, voucher):
@view_config(request_method='DELETE', route_name='api_voucher_id', renderer='json')
@TryCatchFunction
def delete(request):
voucher = Voucher.by_id(uuid.UUID(request.matchdict['id']))
permission = check_delete_permissions(request, voucher)
@ -117,6 +118,7 @@ def delete(request):
@view_config(request_method='GET', route_name='api_voucher_id', renderer='json')
@TryCatchFunction
def get_old(request):
id = request.matchdict.get('id', None)
return voucher_info(Voucher.by_id(uuid.UUID(id)))

View File

@ -1,10 +1,9 @@
import uuid
from pyramid.response import Response
from pyramid.security import authenticated_userid
from pyramid.view import view_defaults, view_config
import transaction
from brewman.models.auth import User
from brewman.models.validation_exception import ValidationError, TryCatchFunction
from brewman.models.validation_exception import TryCatchFunction
from brewman.models.voucher import Voucher
from brewman.views.services.session import session_current_date_set
from brewman.views.services.voucher import voucher_info, journal_create_voucher, purchase_create_voucher, issue_create_voucher