BUG: Missing await keyword in authentication dependency causes crash for logged-in users

オープン
#177 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@OmShukla-07 がすでに取り組んでいます。

2025年12月27日 から。

評価

この issue はまだ評価されていません。

説明

bug
Is there an existing issue for this?
  • I have searched the existing issues
What happened?

🐞 Bug Report: Two Critical Bugs Fixed in PR

Is there an existing issue for this?

  • ✅ I have searched the existing issues

📌 Issue Overview

This PR fixes TWO separate critical bugs that were breaking the backend:

  1. Authentication Bug - Missing await keyword crashes logged-in users
  2. Startup Crash Bug - Weaviate connection failure prevents backend from starting

🔍 Steps to Reproduce

Bug 1: Authentication Crash (dependencies.py)
  1. Go to http://localhost:5173/login
  2. Create an account and log in successfully
  3. Navigate to /integrations page
  4. See the error: AttributeError: 'coroutine' object has no attribute 'user'
Bug 2: Startup Crash (main.py)
  1. Ensure Weaviate is slow to start or has network issues
  2. Run poetry run python main.py in backend directory
  3. Backend crashes with httpcore.ConnectTimeout error
  4. See backend fails to start completely

🎯 Expected Behavior

Bug 1: Authentication
  • Logged-in users should successfully access /integrations page
  • Integration status should load without crashing
  • No AttributeError: 'coroutine' in logs
Bug 2: Startup
  • Backend should start even if Weaviate connection times out
  • Show warning message instead of crashing
  • Other features (Discord bot, API) should work normally

🚨 Actual Behavior

Bug 1: Authentication
AttributeError: 'coroutine' object has no attribute 'user'
INFO: 127.0.0.1:62135 - "GET /v1/integrations/status/discord HTTP/1.1" 401 Unauthorized

Result: Integration page completely broken for logged-in users

Bug 2: Startup
ERROR - Failed to connect to Weaviate: httpcore.ConnectTimeout
Traceback (most recent call last):
  File "D:\FSOCIETY\GSOC\Devr.AI\backend\main.py", line 70, in test_weaviate_connection
    raise

Result: Backend won't start, all services unavailable


📷 Screenshot

Before Fix:

Terminal: Backend crashes during startup
Browser: Cannot access integrations page (if backend somehow starts)

After Fix:

Terminal: 
✅ Weaviate connection successful OR
⚠️  Failed to connect to Weaviate during startup: [error]
⚠️  Continuing without Weaviate - some features may not work
✅ Discord bot logged in as Devr.AI#5824
✅ Uvicorn running on http://0.0.0.0:8000

Browser:
✅ Integration page loads successfully for logged-in users
✅ No AttributeError crashes

💡 Suggested Improvements (Already Implemented)

Fix 1: Add Missing await Keyword

File: backend/app/core/dependencies.py
Line: 50

# BEFORE (Broken):
user_response = supabase.auth.get_user(token)

# AFTER (Fixed):
user_response = await supabase.auth.get_user(token)

Why needed:

  • Supabase uses AsyncClient - all auth methods are async
  • Without await, Python tries to access .user attribute before data loads
  • Bug was introduced by CodeRabbit AI in commit cedaad3 (Oct 16, 2025)
Fix 2: Make Weaviate Connection Non-Blocking

File: backend/main.py
Lines: 68-72

# BEFORE (Broken):
except Exception as e:
    logger.error(f"Failed to connect to Weaviate: {e}")
    raise  # ❌ This crashes entire backend

# AFTER (Fixed):
except Exception as e:
    logger.warning(f"Failed to connect to Weaviate during startup: {e}")
    logger.warning("Continuing without Weaviate - some features may not work")
    # Don't raise - allow backend to start even if Weaviate is unavailable

Why needed:

  • Weaviate client tries to connect to PyPI for version checks during init
  • Network timeouts or slow connections would crash entire backend
  • Backend should gracefully degrade instead of completely failing
  • Discord bot, API endpoints, and other services don't depend on Weaviate to start

🔗 Root Cause Analysis

Bug 1: Authentication

Introduced by: CodeRabbit AI automated refactoring

Commit: cedaad3194a4c2fcd7c5d76aa6f096e17db11f78

Date: October 16, 2025

Original correct code: Commit ee34c94 had await keyword

Git history proof:

$ git show cedaad3 backend/app/core/dependencies.py
-        user_response = await supabase.auth.get_user(token)  # Original (correct)
+        user_response = supabase.auth.get_user(token)        # Bug introduced
Bug 2: Weaviate Startup

Design issue: Original implementation treated Weaviate connection failure as fatal

Problem: Weaviate tries to connect to https://pypi.org/pypi/weaviate-client/json during startup

Result: Network issues or slow connections crash entire backend

Why not caught earlier:

  • Weaviate usually starts quickly in Docker
  • Most testing done in environments with good network connectivity
  • Bug only appears when Weaviate is slow or network has issues

📊 Impact Assessment

Bug 1: Authentication

Severity: 🔴 Critical
Affected users: All logged-in dashboard users
Broken features:

  • Integration status page
  • Integration management
  • Settings page
  • Any authenticated API endpoint

Working features (unaffected):

  • Discord bot commands
  • Public landing page
  • User registration
  • Login (authentication itself)
Bug 2: Weaviate Startup

Severity: 🔴 Critical
Affected users: Everyone (backend won't start)
Broken features:

  • Entire backend unavailable
  • Discord bot can't connect
  • All API endpoints down
  • Frontend can't fetch data

Record

  • ✅ I agree to follow this project's Code of Conduct
  • ✅ I want to work on this issue (already fixed in PR)

Related Files
  • backend/app/core/dependencies.py - Authentication fix
  • backend/main.py - Startup robustness fix
  • backend/app/database/supabase/client.py - AsyncClient usage
  • docs/issues/ISSUE_002_Missing_Await_In_Auth_Dependency.md - Detailed documentation
References

Report created by: Om Shukla (@OmShukla-07)
Date: December 1, 2025

Record
  • I agree to follow this project's Code of Conduct
  • I want to work on this issue
主要言語
Python
スター
103
フォーク
143
PR マージ指標
30日以内にマージされた PR はありません

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

AOSSIE-Org/Devr.AI のほかの issue

AOSSIE-Org/Devr.AI の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。