Skip to content

Commit 6233553

Browse files
committed
fix: KeyError in clear_session + replace deprecated use_container_width
1 parent e663e10 commit 6233553

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

frontend/components/charts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def render_radar_chart(input_data: dict):
4040
margin=dict(l=40, r=40, t=40, b=40)
4141
)
4242

43-
st.plotly_chart(fig, use_container_width=True)
43+
st.plotly_chart(fig, use_container_width=True) # Still valid for plotly_chart
4444

4545
def render_trend_chart(records: list, metric_key: str, label: str):
4646
"""
@@ -73,4 +73,4 @@ def render_trend_chart(records: list, metric_key: str, label: str):
7373
fig = px.line(df, x="Date", y=label, markers=True, title=f"{label} Over Time")
7474
fig.update_layout(xaxis_title="Checkup Date", yaxis_title=label)
7575

76-
st.plotly_chart(fig, use_container_width=True)
76+
st.plotly_chart(fig, use_container_width=True) # Still valid for plotly_chart

frontend/components/sidebar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def render_sidebar():
341341

342342
# --- 7. SIGN OUT BUTTON ---
343343
st.markdown("<div style='height: 0.75rem'></div>", unsafe_allow_html=True)
344-
if st.button("🚪 Sign Out", type="secondary", use_container_width=True, key="logout_btn"):
344+
if st.button("🚪 Sign Out", type="secondary", width="stretch", key="logout_btn"):
345345
api.clear_session()
346346
st.rerun()
347347

frontend/utils/api.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,17 @@ def load_session() -> Optional[Dict[str, str]]:
3636

3737
def clear_session():
3838
cm = _get_cookie_manager()
39-
cm.delete("auth_token", key="del_token")
40-
cm.delete("auth_username", key="del_user")
39+
# Check if cookie exists before deleting to avoid KeyError
40+
try:
41+
if cm.get("auth_token"):
42+
cm.delete("auth_token", key="del_token")
43+
except Exception:
44+
pass
45+
try:
46+
if cm.get("auth_username"):
47+
cm.delete("auth_username", key="del_user")
48+
except Exception:
49+
pass
4150
st.session_state.pop('token', None)
4251
st.session_state.pop('username', None)
4352

frontend/views/auth_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def render_auth_page():
116116
with st.form("login", border=False):
117117
u = st.text_input("Username", placeholder="Enter username", label_visibility="collapsed")
118118
p = st.text_input("Password", type="password", placeholder="Enter password", label_visibility="collapsed")
119-
if st.form_submit_button("Sign In →", type="primary", use_container_width=True):
119+
if st.form_submit_button("Sign In →", type="primary", width="stretch"):
120120
if api.login(u, p): st.rerun()
121121

122122
with tab2:
@@ -125,7 +125,7 @@ def render_auth_page():
125125
us = st.text_input("Username", placeholder="Choose a username", label_visibility="collapsed")
126126
em = st.text_input("Email", placeholder="Your email", label_visibility="collapsed")
127127
pw = st.text_input("Password", type="password", placeholder="Create password", label_visibility="collapsed")
128-
if st.form_submit_button("Create Account", type="primary", use_container_width=True):
128+
if st.form_submit_button("Create Account", type="primary", width="stretch"):
129129
if api.signup(us, pw, em, us, "2000-01-01"): # Use username as name initially
130130
if api.login(us, pw): st.rerun()
131131

frontend/views/chat_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,6 @@ def render_chat_page():
236236
st.markdown("<br>", unsafe_allow_html=True)
237237
col1, col2, col3 = st.columns([1, 1, 1])
238238
with col2:
239-
if st.button("🗑️ Clear Chat", type="secondary", use_container_width=True):
239+
if st.button("🗑️ Clear Chat", type="secondary", width="stretch"):
240240
st.session_state.messages = []
241241
st.rerun()

frontend/views/pricing_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def render_pricing_page():
118118
<div style="background: linear-gradient(180deg, rgba(37, 99, 235, 0.05), rgba(59, 130, 246, 0.02)); border: 2px solid #3B82F6; border-top: none; border-radius: 0 0 16px 16px; padding: 0 2rem 2rem 2rem; text-align: center;">
119119
""", unsafe_allow_html=True)
120120

121-
if st.button("Upgrade Now", key="upgrade_pro", type="primary", use_container_width=True):
121+
if st.button("Upgrade Now", key="upgrade_pro", type="primary", width="stretch"):
122122
with st.spinner("Initializing Payment..."):
123123
# Create Order (999 INR = 99900 paise)
124124
resp = api.create_payment_order(99900, "pro_tier")

0 commit comments

Comments
 (0)