anderson-ufrj commited on
Commit
c76ac1d
·
1 Parent(s): 3177117

fix(db): skip PostgreSQL initialization on HuggingFace Spaces

Browse files

HuggingFace Spaces blocks direct PostgreSQL connections (port 5432).
Detect SPACE_ID environment variable and skip connection pool initialization.

The investigation_service_selector will automatically use REST API services
instead, which work over HTTP/HTTPS (ports 80/443).

Files changed (1) hide show
  1. src/db/session.py +11 -1
src/db/session.py CHANGED
@@ -43,6 +43,17 @@ get_db = get_session
43
 
44
  async def init_database():
45
  """Initialize database connection pools."""
 
 
 
 
 
 
 
 
 
 
 
46
  try:
47
  await connection_pool_service.initialize()
48
  logger.info("Database connection pools initialized")
@@ -53,7 +64,6 @@ async def init_database():
53
  exc_info=True
54
  )
55
  # Don't raise - allow app to start without database
56
- # This is needed for HuggingFace Spaces deployment
57
  logger.warning("Running without database connection - some features may be limited")
58
 
59
 
 
43
 
44
  async def init_database():
45
  """Initialize database connection pools."""
46
+ import os
47
+
48
+ # Skip PostgreSQL direct connection on HuggingFace Spaces
49
+ # HuggingFace blocks port 5432, use REST API services instead
50
+ is_huggingface = os.getenv("SPACE_ID") is not None or os.getenv("SPACE_AUTHOR_NAME") is not None
51
+
52
+ if is_huggingface:
53
+ logger.info("HuggingFace Spaces detected - skipping direct PostgreSQL connection")
54
+ logger.info("Using Supabase REST API services for data persistence")
55
+ return
56
+
57
  try:
58
  await connection_pool_service.initialize()
59
  logger.info("Database connection pools initialized")
 
64
  exc_info=True
65
  )
66
  # Don't raise - allow app to start without database
 
67
  logger.warning("Running without database connection - some features may be limited")
68
 
69