Trying to catch database locked error
This commit is contained in:
parent
f0e3ba19e8
commit
6b89a93bde
@ -1,4 +1,5 @@
|
|||||||
from pyramid.response import Response
|
from pyramid.response import Response
|
||||||
|
from sqlalchemy.exc import OperationalError
|
||||||
import transaction
|
import transaction
|
||||||
|
|
||||||
class ValidationError(Exception):
|
class ValidationError(Exception):
|
||||||
@ -17,7 +18,7 @@ def TryCatchFunction(f):
|
|||||||
def _decorator(self, *args, **kwargs):
|
def _decorator(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
except (ValidationError, ValueError, KeyError, AttributeError, TypeError) as ex:
|
except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError) as ex:
|
||||||
transaction.abort()
|
transaction.abort()
|
||||||
response = Response("Failed validation: {0}".format(str(ex)))
|
response = Response("Failed validation: {0}".format(str(ex)))
|
||||||
response.status_int = 500
|
response.status_int = 500
|
||||||
|
@ -77,6 +77,7 @@ def check_delete_permissions(request, voucher):
|
|||||||
|
|
||||||
|
|
||||||
@view_config(request_method='DELETE', route_name='api_voucher_id', renderer='json')
|
@view_config(request_method='DELETE', route_name='api_voucher_id', renderer='json')
|
||||||
|
@TryCatchFunction
|
||||||
def delete(request):
|
def delete(request):
|
||||||
voucher = Voucher.by_id(uuid.UUID(request.matchdict['id']))
|
voucher = Voucher.by_id(uuid.UUID(request.matchdict['id']))
|
||||||
permission = check_delete_permissions(request, voucher)
|
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')
|
@view_config(request_method='GET', route_name='api_voucher_id', renderer='json')
|
||||||
|
@TryCatchFunction
|
||||||
def get_old(request):
|
def get_old(request):
|
||||||
id = request.matchdict.get('id', None)
|
id = request.matchdict.get('id', None)
|
||||||
return voucher_info(Voucher.by_id(uuid.UUID(id)))
|
return voucher_info(Voucher.by_id(uuid.UUID(id)))
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from pyramid.response import Response
|
|
||||||
from pyramid.security import authenticated_userid
|
from pyramid.security import authenticated_userid
|
||||||
from pyramid.view import view_defaults, view_config
|
from pyramid.view import view_defaults, view_config
|
||||||
import transaction
|
import transaction
|
||||||
from brewman.models.auth import User
|
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.models.voucher import Voucher
|
||||||
from brewman.views.services.session import session_current_date_set
|
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
|
from brewman.views.services.voucher import voucher_info, journal_create_voucher, purchase_create_voucher, issue_create_voucher
|
||||||
|
Loading…
Reference in New Issue
Block a user