-
Notifications
You must be signed in to change notification settings - Fork 140
This pull request addresses the dependency vulnerabilities described in #115 #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Muneerali199
wants to merge
5
commits into
AOSSIE-Org:main
Choose a base branch
from
Muneerali199:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ec981f
update dependency
Muneerali199 b98085d
fix dark mode toggle functioning onclick
Muneerali199 701632d
Fix AI route env handling and lazy Supabase Client (closes #263 )
Muneerali199 1a83d86
Use async Supabase client via app.state (refs #263)
Muneerali199 977eb70
Harden Supabase async client init logging
Muneerali199 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,11 @@ dist-ssr | |
| *.sln | ||
| *.sw? | ||
|
|
||
| # Env files | ||
| .env | ||
| Backend/.env | ||
| Frontend/.env | ||
|
|
||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env python | ||
| """ | ||
| Test to verify the ai.py fix: import-time env validation is removed. | ||
| This demonstrates the fix works without needing Supabase/Gemini keys at import. | ||
| """ | ||
| import os | ||
| import sys | ||
|
|
||
| # Clear all env vars that were previously required at import | ||
| os.environ.pop('SUPABASE_URL', None) | ||
| os.environ.pop('SUPABASE_KEY', None) | ||
| os.environ.pop('GEMINI_API_KEY', None) | ||
|
|
||
| print("=" * 70) | ||
| print("TEST: Import ai.py with missing env vars (should NOT crash)") | ||
| print("=" * 70) | ||
|
|
||
| try: | ||
| # This import would fail BEFORE the fix with: | ||
| # ValueError: Missing required environment variables: SUPABASE_URL, SUPABASE_KEY, GEMINI_API_KEY | ||
| from app.routes import ai | ||
| print("✓ SUCCESS: ai.py imported without crashing!") | ||
| print(" - No ValueError on missing SUPABASE_URL/SUPABASE_KEY/GEMINI_API_KEY") | ||
| print(" - Router and helper functions are available") | ||
| print("\nHelper functions available:") | ||
| print(f" - get_supabase_client: {hasattr(ai, 'get_supabase_client')}") | ||
| print(f" - get_gemini_api_key: {hasattr(ai, 'get_gemini_api_key')}") | ||
| print(f" - fetch_from_gemini: {hasattr(ai, 'fetch_from_gemini')}") | ||
| print(f" - trending_niches: {hasattr(ai, 'trending_niches')}") | ||
|
|
||
| print("\n" + "=" * 70) | ||
| print("TEST: Verify per-request env validation") | ||
| print("=" * 70) | ||
|
|
||
| # Test 1: Try to get Supabase client without env vars | ||
| print("\nTest 1: get_supabase_client() without SUPABASE_URL/KEY...") | ||
| try: | ||
| client = ai.get_supabase_client() | ||
| print(" ✗ FAIL: Should have raised HTTPException") | ||
| except Exception as e: | ||
| if "Supabase configuration missing" in str(e): | ||
| print(f" ✓ PASS: Raised HTTPException with message: {e}") | ||
| else: | ||
| print(f" ✗ FAIL: Wrong exception: {type(e).__name__}: {e}") | ||
|
|
||
| # Test 2: Try to get Gemini key without env var | ||
| print("\nTest 2: get_gemini_api_key() without GEMINI_API_KEY...") | ||
| try: | ||
| key = ai.get_gemini_api_key() | ||
| print(" ✗ FAIL: Should have raised HTTPException") | ||
| except Exception as e: | ||
| if "Gemini API key not configured" in str(e): | ||
| print(f" ✓ PASS: Raised HTTPException with message: {e}") | ||
| else: | ||
| print(f" ✗ FAIL: Wrong exception: {type(e).__name__}: {e}") | ||
|
|
||
| # Test 3: Set env vars and verify client creation would proceed | ||
| print("\nTest 3: Setting env vars and retrying get_supabase_client()...") | ||
| os.environ['SUPABASE_URL'] = 'https://test.supabase.co' | ||
| os.environ['SUPABASE_KEY'] = 'test_key_123' | ||
| try: | ||
| # Note: This will fail when trying to actually connect, but the env check passes | ||
| client = ai.get_supabase_client() | ||
| print(" - Got to client creation (would connect to real Supabase now)") | ||
| except Exception as e: | ||
| if "Supabase configuration missing" not in str(e): | ||
| print(f" ✓ PASS: Passed env check, failed on actual connection: {type(e).__name__}") | ||
| else: | ||
| print(f" ✗ FAIL: Still failing on env check: {e}") | ||
|
|
||
| print("\n" + "=" * 70) | ||
| print("SUMMARY") | ||
| print("=" * 70) | ||
| print("✓ Fix verified: ai.py no longer crashes at import time") | ||
| print("✓ Env validation moved to per-request helpers") | ||
| print("✓ Returns clear 500 errors when config is missing") | ||
| print("✓ API can start and serve other routes while missing keys") | ||
|
|
||
| except ImportError as e: | ||
| print(f"✗ FAIL: Could not import app.routes.ai: {e}") | ||
| print(" Make sure fastapi and supabase packages are installed") | ||
| sys.exit(1) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant exception parameter from
logging.exception.The
logging.exception()method automatically includes the exception traceback and message, so passingexcas a format parameter is redundant.🔎 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.14.10)
44-44: Redundant exception object included in
logging.exceptioncall(TRY401)
🤖 Prompt for AI Agents