From 32ac3bc96fdbfa44a8eea5dc840fe630bf6ad04e Mon Sep 17 00:00:00 2001 From: Nuwan Samarasinghe Date: Tue, 15 Oct 2024 17:35:03 +0100 Subject: [PATCH] adding fixes for 500 error for wild card urls --- app/helpers.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/helpers.py b/app/helpers.py index 97158aa5..f2d91d27 100644 --- a/app/helpers.py +++ b/app/helpers.py @@ -141,7 +141,9 @@ def format_rehydrate_payload( def find_round_short_name_in_request(): - if round_short_name := request.view_args.get("round_short_name") or request.args.get("round"): + if round_short_name := (request.view_args and request.view_args.get("round_short_name")) or ( + request.args and request.args.get("round") + ): return round_short_name else: return None @@ -149,9 +151,9 @@ def find_round_short_name_in_request(): def find_round_id_in_request(): if ( - application_id := request.args.get("application_id") - or request.view_args.get("application_id") - or request.form.get("application_id") + application_id := (request.args and request.args.get("application_id")) + or (request.view_args and request.view_args.get("application_id")) + or (request.form and request.form.get("application_id")) ): application = get_application_data(application_id) return application.round_id @@ -160,12 +162,14 @@ def find_round_id_in_request(): def find_fund_id_in_request(): - if fund_id := request.view_args.get("fund_id") or request.args.get("fund_id"): + if fund_id := (request.view_args and request.view_args.get("fund_id")) or ( + request.args and request.args.get("fund_id") + ): return fund_id elif ( - application_id := request.args.get("application_id") - or request.view_args.get("application_id") - or request.form.get("application_id") + application_id := (request.args and request.args.get("application_id")) + or (request.view_args and request.view_args.get("application_id")) + or (request.form and request.form.get("application_id")) ): application = get_application_data(application_id) return application.fund_id @@ -174,9 +178,10 @@ def find_fund_id_in_request(): def find_fund_short_name_in_request(): - if (fund_short_name := request.view_args.get("fund_short_name") or request.args.get("fund")) and str.upper( - fund_short_name - ) in get_all_fund_short_names(): + if ( + fund_short_name := (request.view_args and request.view_args.get("fund_short_name")) + or (request.args and request.args.get("fund")) + ) and (fund_short_name and (str.upper(fund_short_name) in get_all_fund_short_names())): return fund_short_name else: return None