Fix configuration architecture: Add dotenv loading and use app.config consistently
Address architectural inconsistency where environment variables were used
directly instead of through Flask's configuration system.
Issues Fixed:
1. .env file was never loaded - load_dotenv() was missing
2. Routes used os.getenv() directly instead of app.config
3. ANTHROPIC_API_KEY was defined in config but not used properly
Changes:
- config/development.py: Added load_dotenv() at module level
- app/routes/submission.py: Changed os.getenv() to current_app.config.get()
- app/routes/dashboard.py: Changed os.getenv() to current_app.config.get()
Benefits:
- Proper separation of concerns (config vs code)
- .env files now work as expected in development
- Easier to test (can mock app.config)
- Consistent with Flask best practices
- Production env vars still work (no dotenv in production config)
Configuration Flow:
Development: .env → load_dotenv() → os.environ → DevelopmentConfig → app.config
Production: System env vars → os.environ → ProductionConfig → app.config
Application: app.config.get('ANTHROPIC_API_KEY')
All 49 tests passing (1 skipped)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -248,11 +248,11 @@ def trigger_analysis(feedback_id):
|
|||||||
actual_product_id, feedback_id, 'analyzing'
|
actual_product_id, feedback_id, 'analyzing'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get API key from environment
|
# Get API key from app configuration
|
||||||
api_key = os.getenv('ANTHROPIC_API_KEY')
|
api_key = current_app.config.get('ANTHROPIC_API_KEY')
|
||||||
|
|
||||||
if not api_key:
|
if not api_key:
|
||||||
raise Exception("ANTHROPIC_API_KEY not configured")
|
raise Exception("ANTHROPIC_API_KEY not configured in app settings")
|
||||||
|
|
||||||
# Initialize analyzer
|
# Initialize analyzer
|
||||||
analyzer = ClaudeAnalyzer(api_key=api_key)
|
analyzer = ClaudeAnalyzer(api_key=api_key)
|
||||||
|
|||||||
@@ -146,11 +146,11 @@ def _analyze_feedback_background(app, product_id, feedback_id, feedback_text, ta
|
|||||||
product_id, feedback_id, 'analyzing'
|
product_id, feedback_id, 'analyzing'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get API key from environment
|
# Get API key from app configuration
|
||||||
api_key = os.getenv('ANTHROPIC_API_KEY')
|
api_key = current_app.config.get('ANTHROPIC_API_KEY')
|
||||||
|
|
||||||
if not api_key:
|
if not api_key:
|
||||||
raise Exception("ANTHROPIC_API_KEY not configured")
|
raise Exception("ANTHROPIC_API_KEY not configured in app settings")
|
||||||
|
|
||||||
# Initialize analyzer
|
# Initialize analyzer
|
||||||
analyzer = ClaudeAnalyzer(api_key=api_key)
|
analyzer = ClaudeAnalyzer(api_key=api_key)
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
"""Development configuration"""
|
"""Development configuration"""
|
||||||
import os
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Load .env file for development
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
class DevelopmentConfig:
|
class DevelopmentConfig:
|
||||||
"""Development environment configuration"""
|
"""Development environment configuration"""
|
||||||
|
|||||||
Reference in New Issue
Block a user