Edwin Salguero commited on
Commit
81fb9e2
·
1 Parent(s): 081f523

Fix FRED API key propagation - make key loading dynamic instead of static at module import time

Browse files
Files changed (1) hide show
  1. frontend/app.py +8 -6
frontend/app.py CHANGED
@@ -67,8 +67,8 @@ def load_analytics():
67
  print(f"DEBUG: Analytics loading failed: {e}, ANALYTICS_AVAILABLE = {ANALYTICS_AVAILABLE}")
68
  return False
69
 
70
- # Get FRED API key from environment
71
- FRED_API_KEY = os.getenv('FRED_API_KEY', '')
72
 
73
  # Lazy import FRED API client
74
  def load_fred_client():
@@ -97,18 +97,20 @@ def load_config():
97
 
98
  print("DEBUG: Final FRED_API_KEY =", fred_key)
99
 
 
 
 
 
100
  try:
101
  from config import Config
102
  CONFIG_AVAILABLE = True
103
  if not fred_key:
104
  fred_key = Config.get_fred_api_key()
105
- FRED_API_KEY = fred_key
106
- REAL_DATA_MODE = Config.validate_fred_api_key() if fred_key else False
107
  return True
108
  except ImportError:
109
  CONFIG_AVAILABLE = False
110
- FRED_API_KEY = fred_key
111
- REAL_DATA_MODE = FRED_API_KEY and FRED_API_KEY != 'your-fred-api-key-here'
112
  return False
113
 
114
  # Custom CSS for enterprise styling
 
67
  print(f"DEBUG: Analytics loading failed: {e}, ANALYTICS_AVAILABLE = {ANALYTICS_AVAILABLE}")
68
  return False
69
 
70
+ # Get FRED API key from environment (will be updated by load_config())
71
+ FRED_API_KEY = ''
72
 
73
  # Lazy import FRED API client
74
  def load_fred_client():
 
97
 
98
  print("DEBUG: Final FRED_API_KEY =", fred_key)
99
 
100
+ # Update global variables
101
+ FRED_API_KEY = fred_key or ''
102
+ REAL_DATA_MODE = FRED_API_KEY and FRED_API_KEY != 'your-fred-api-key-here'
103
+
104
  try:
105
  from config import Config
106
  CONFIG_AVAILABLE = True
107
  if not fred_key:
108
  fred_key = Config.get_fred_api_key()
109
+ FRED_API_KEY = fred_key
110
+ REAL_DATA_MODE = Config.validate_fred_api_key() if fred_key else False
111
  return True
112
  except ImportError:
113
  CONFIG_AVAILABLE = False
 
 
114
  return False
115
 
116
  # Custom CSS for enterprise styling