From 92d3cc1c7da5c1b3dceebefe15918a2e156879ab Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Wed, 13 Jan 2016 18:36:22 +0100 Subject: [PATCH] Change get query for scheduled operation. --- accountant/api/views/scheduled_operations.py | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/accountant/api/views/scheduled_operations.py b/accountant/api/views/scheduled_operations.py index 74e9fb3..b6bf428 100644 --- a/accountant/api/views/scheduled_operations.py +++ b/accountant/api/views/scheduled_operations.py @@ -19,7 +19,6 @@ import dateutil.parser from flask.ext.restful import Resource, fields, reqparse, marshal_with_field from sqlalchemy import true -from sqlalchemy.orm.exc import NoResultFound from accountant import db @@ -99,13 +98,13 @@ class ScheduledOperationResource(Resource): """ Get scheduled operation. """ - try: - return ScheduledOperation.query().filter( - ScheduledOperation.id == id - ).one(), 200 - except NoResultFound: + scheduled_operation = ScheduledOperation.query().get(id) + + if not scheduled_operation: return None, 404 + return scheduled_operation, 200 + @requires_auth @marshal_with_field(Object(scheduled_operation_model)) def post(self, id): @@ -117,11 +116,9 @@ class ScheduledOperationResource(Resource): assert (id not in data or data.id is None or data.id == id) - try: - scheduled_operation = ScheduledOperation.query().filter( - ScheduledOperation.id == id - ).one() - except NoResultFound: + scheduled_operation = ScheduledOperation.query().get(id) + + if not scheduled_operation: return None, 404 # SQLAlchemy objects ignore __dict__.update() with merge. @@ -142,11 +139,9 @@ class ScheduledOperationResource(Resource): """ Delete a scheduled operation. """ - try: - scheduled_operation = ScheduledOperation.query().filter( - ScheduledOperation.id == id - ).one() - except NoResultFound: + scheduled_operation = ScheduledOperation.query().get(id) + + if not scheduled_operation: return None, 404 operations = scheduled_operation.operations.filter(