From e75773733c6059623da6cf4d36dbf44a696f0a8b Mon Sep 17 00:00:00 2001 From: Eric0801 <33929918+Eric0801@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:19:24 +0800 Subject: [PATCH] fix: use role_map.get() to handle missing role keys safely - Replace role_map[key] with role_map.get(key, key) to prevent KeyError - Affects result_view and custom routes - Ensures backward compatibility with old strategy data - Fixes issue where strategies with unmapped roles cause page crashes --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 6db365e..7ed1e04 100644 --- a/main.py +++ b/main.py @@ -437,7 +437,7 @@ def custom_post(): info = MVO.portfolio_info(np.array([1]), rets['Portfolio'].to_numpy().reshape(-1, 1), np.zeros(len(ret)-lookback)) info['username'] = session.get('username').split('@')[0] - info['role'] = role_map[role] + info['role'] = role_map.get(role, role) info['id']='Custom data' info['name']='Custom data' info['date'] = '-' @@ -547,7 +547,7 @@ def result_view(): conn.close() # Processing data data = dict(data) - data['role'] = role_map[data['role']] + data['role'] = role_map.get(data['role'], data['role']) w = data['weight'] r = data['ret'] w = pd.DataFrame(w['data'], columns=w['columns'], index=w['index'])