Add type=int to request.args.get, if the arg is an int it's returned else None. This means we ignore the arg if its the wrong data type and we don't need to handle the error.

This commit is contained in:
Rebecca Law
2019-12-06 13:10:38 +00:00
parent 203e19bef3
commit 921b90cdec
4 changed files with 28 additions and 37 deletions

View File

@@ -10,6 +10,8 @@ from app.utils import midnight_n_days_ago
def dao_get_uploads_by_service_id(service_id, limit_days=None, page=1, page_size=50):
# Hardcoded filter to exclude cancelled or scheduled jobs
# for the moment, but we may want to change this method take 'statuses' as a argument in the future
jobs_query_filter = [
Job.service_id == service_id,
Job.original_file_name != current_app.config['TEST_MESSAGE_FILENAME'],

View File

@@ -12,7 +12,6 @@ from app.dao.jobs_dao import (
from app.dao.uploads_dao import dao_get_uploads_by_service_id
from app.errors import (
register_errors,
InvalidRequest
)
from app.utils import pagination_links, midnight_n_days_ago
@@ -23,17 +22,9 @@ register_errors(upload_blueprint)
@upload_blueprint.route('', methods=['GET'])
def get_uploads_by_service(service_id):
if request.args.get('limit_days'):
try:
limit_days = int(request.args['limit_days'])
except ValueError:
errors = {'limit_days': ['{} is not an integer'.format(request.args['limit_days'])]}
raise InvalidRequest(errors, status_code=400)
else:
limit_days = None
page = int(request.args.get('page', 1))
return jsonify(**get_paginated_uploads(service_id, limit_days, page))
return jsonify(**get_paginated_uploads(service_id,
request.args.get('limit_days', type=int),
request.args.get('page', type=int)))
def get_paginated_uploads(service_id, limit_days, page):