From 51d1740bc070efec74f9e04f718848ab29380b81 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Fri, 17 Oct 2025 09:45:31 +0200 Subject: [PATCH] Fix configuration architecture: Add dotenv loading and use app.config consistently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/routes/dashboard.py | 6 +++--- app/routes/submission.py | 6 +++--- config/development.py | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/routes/dashboard.py b/app/routes/dashboard.py index 2492665..cb46cf4 100644 --- a/app/routes/dashboard.py +++ b/app/routes/dashboard.py @@ -248,11 +248,11 @@ def trigger_analysis(feedback_id): actual_product_id, feedback_id, 'analyzing' ) - # Get API key from environment - api_key = os.getenv('ANTHROPIC_API_KEY') + # Get API key from app configuration + api_key = current_app.config.get('ANTHROPIC_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 analyzer = ClaudeAnalyzer(api_key=api_key) diff --git a/app/routes/submission.py b/app/routes/submission.py index 03df5b9..93a14b0 100644 --- a/app/routes/submission.py +++ b/app/routes/submission.py @@ -146,11 +146,11 @@ def _analyze_feedback_background(app, product_id, feedback_id, feedback_text, ta product_id, feedback_id, 'analyzing' ) - # Get API key from environment - api_key = os.getenv('ANTHROPIC_API_KEY') + # Get API key from app configuration + api_key = current_app.config.get('ANTHROPIC_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 analyzer = ClaudeAnalyzer(api_key=api_key) diff --git a/config/development.py b/config/development.py index 64d4ec7..ccb8dec 100644 --- a/config/development.py +++ b/config/development.py @@ -1,5 +1,9 @@ """Development configuration""" import os +from dotenv import load_dotenv + +# Load .env file for development +load_dotenv() class DevelopmentConfig: """Development environment configuration"""