Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import sys | |
| import os | |
| sys.path.append(os.path.join(os.path.dirname(__file__), 'src')) | |
| from utils import init_supabase, get_student_debate_case | |
| def main(): | |
| st.title("π Week 4 Debate Case Debug") | |
| st.markdown("---") | |
| # Test 1: Supabase Connection | |
| st.subheader("1. Testing Supabase Connection") | |
| try: | |
| supabase = init_supabase() | |
| if supabase: | |
| st.success("β Supabase connection successful") | |
| else: | |
| st.error("β Supabase connection failed") | |
| return | |
| except Exception as e: | |
| st.error(f"β Supabase connection error: {str(e)}") | |
| return | |
| # Test 2: Check if table exists | |
| st.subheader("2. Testing student_debate_case table") | |
| try: | |
| response = supabase.table('student_debate_case').select('*').limit(1).execute() | |
| st.success(f"β Table accessible, found {len(response.data)} records") | |
| except Exception as e: | |
| st.error(f"β Table access error: {str(e)}") | |
| return | |
| # Test 3: List all records | |
| st.subheader("3. Listing all debate cases in table") | |
| try: | |
| response = supabase.table('student_debate_case').select('*').execute() | |
| if response.data: | |
| st.success(f"β Found {len(response.data)} debate cases:") | |
| for i, case in enumerate(response.data, 1): | |
| st.write(f" **{i}.** Student ID: `{case.get('student_id', 'N/A')}`") | |
| st.write(f" Link: {case.get('google_doc_link', 'N/A')}") | |
| st.write(f" Created: {case.get('created_at', 'N/A')}") | |
| st.write("---") | |
| else: | |
| st.warning("β No debate cases found in table") | |
| except Exception as e: | |
| st.error(f"β Error listing cases: {str(e)}") | |
| # Test 4: Test with specific usernames | |
| st.subheader("4. Testing with specific usernames") | |
| test_usernames = ["lily", "reed", "instructor", "admin"] | |
| for username in test_usernames: | |
| try: | |
| result = get_student_debate_case(username) | |
| if result: | |
| st.success(f"β Found case for '{username}': {result.get('google_doc_link', 'N/A')}") | |
| else: | |
| st.info(f"β No case found for '{username}'") | |
| except Exception as e: | |
| st.error(f"β Error testing '{username}': {str(e)}") | |
| # Test 5: Test with current user | |
| st.subheader("5. Testing with current user") | |
| if st.session_state.get('authenticated', False): | |
| username = st.session_state.get('username') | |
| st.write(f"**Current user:** {username}") | |
| try: | |
| result = get_student_debate_case(username) | |
| if result: | |
| st.success(f"β Found case for current user '{username}': {result.get('google_doc_link', 'N/A')}") | |
| else: | |
| st.warning(f"β No case found for current user '{username}'") | |
| except Exception as e: | |
| st.error(f"β Error testing current user: {str(e)}") | |
| else: | |
| st.warning("β οΈ No user currently authenticated") | |
| # Test 6: Check RLS policies | |
| st.subheader("6. RLS Policy Check") | |
| st.info(""" | |
| **RLS Policies Applied:** | |
| - Users can read their own debate cases | |
| - Users can insert their own debate cases | |
| - Users can update their own debate cases | |
| - Users can delete their own debate cases | |
| **Note:** If you're testing with a service role or admin user, you might need additional policies. | |
| """) | |
| if __name__ == "__main__": | |
| main() |