Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Debug script for Week 4 debate case functionality | |
| Run this script to test if student debate cases are being retrieved correctly | |
| """ | |
| import os | |
| import sys | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src')) | |
| # Import Supabase directly for testing | |
| from supabase import create_client, Client | |
| def debug_week4_debate_case(): | |
| """Debug the Week 4 debate case functionality""" | |
| print("π Debugging Week 4 Debate Case Functionality") | |
| print("=" * 60) | |
| # Test 1: Supabase Connection | |
| print("1. Testing Supabase Connection...") | |
| try: | |
| # Get credentials from environment variables | |
| url = os.getenv("SUPABASE_URL") | |
| key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") # Use service role key | |
| if not url or not key: | |
| print(" β Missing Supabase credentials in environment variables") | |
| print(f" SUPABASE_URL: {'Set' if url else 'Missing'}") | |
| print(f" SUPABASE_SERVICE_ROLE_KEY: {'Set' if key else 'Missing'}") | |
| print(" π‘ Make sure to set SUPABASE_SERVICE_ROLE_KEY environment variable") | |
| return | |
| # Create Supabase client directly with service role | |
| supabase = create_client(url, key) | |
| print(" β Supabase connection successful (using service role)") | |
| except Exception as e: | |
| print(f" β Supabase connection error: {str(e)}") | |
| return | |
| # Test 2: Check if table exists | |
| print("\n2. Testing student_debate_case table...") | |
| try: | |
| response = supabase.table('student_debate_case').select('*').limit(1).execute() | |
| print(f" β Table accessible, found {len(response.data)} records") | |
| except Exception as e: | |
| print(f" β Table access error: {str(e)}") | |
| return | |
| # Test 3: List all records | |
| print("\n3. Listing all debate cases in table...") | |
| try: | |
| response = supabase.table('student_debate_case').select('*').execute() | |
| if response.data: | |
| print(f" β Found {len(response.data)} debate cases:") | |
| for i, case in enumerate(response.data, 1): | |
| print(f" {i}. Student ID: {case.get('student_id', 'N/A')}") | |
| print(f" Google Doc: {case.get('google_doc_link', 'N/A')}") | |
| print(f" Description: {case.get('description', 'N/A')}") | |
| print(f" Created: {case.get('created_at', 'N/A')}") | |
| print() | |
| else: | |
| print(" β No debate cases found in table") | |
| except Exception as e: | |
| print(f" β Error listing cases: {str(e)}") | |
| # Test 4: Test with specific usernames | |
| print("\n4. Testing with specific usernames...") | |
| test_usernames = ["test_student", "student1", "demo_user", "admin"] | |
| for username in test_usernames: | |
| try: | |
| # Test the query directly | |
| response = supabase.table('student_debate_case').select('*').eq('student_id', username).order('created_at', desc=True).limit(1).execute() | |
| if response.data: | |
| print(f" β Found case for '{username}': {response.data[0].get('google_doc_link', 'N/A')}") | |
| else: | |
| print(f" β No case found for '{username}'") | |
| except Exception as e: | |
| print(f" β Error testing '{username}': {str(e)}") | |
| # Test 5: Check environment variables | |
| print("\n5. Checking environment variables...") | |
| try: | |
| url = os.getenv("SUPABASE_URL") | |
| key = os.getenv("SUPABASE_KEY") | |
| if url: | |
| print(f" β SUPABASE_URL found: {url[:20]}...") | |
| else: | |
| print(" β SUPABASE_URL not found") | |
| if key: | |
| print(f" β SUPABASE_KEY found: {key[:10]}...") | |
| else: | |
| print(" β SUPABASE_KEY not found") | |
| except Exception as e: | |
| print(f" β Error checking environment: {str(e)}") | |
| if __name__ == "__main__": | |
| debug_week4_debate_case() |