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
master
Eric0801 2 months ago
parent efbb22494e
commit e75773733c
  1. 4
      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'])

Loading…
Cancel
Save