From e03d27edd90b0be53da3144ca789d8629098fc0c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 25 Apr 2026 22:05:51 +0800 Subject: [PATCH] fix(init): remove auto database initialization from module load Database initialization should not run on every module load as it would risk data loss. Tables should be created/maintained separately. --- hermes_web_cli/init.py | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/hermes_web_cli/init.py b/hermes_web_cli/init.py index 9b2e475..3beab4a 100644 --- a/hermes_web_cli/init.py +++ b/hermes_web_cli/init.py @@ -33,22 +33,6 @@ def load_hermes_web_cli(): """ from ahserver.serverenv import ServerEnv - # Initialize database tables if needed - try: - from .init_db import init_database - import asyncio - # Run database initialization in a new event loop if needed - try: - asyncio.get_running_loop() - # If we're already in an async context, create a task - asyncio.create_task(init_database()) - except RuntimeError: - # No running loop, run synchronously - asyncio.run(init_database()) - except Exception as e: - print(f"Warning: Database initialization failed: {str(e)}") - # Continue loading even if DB init fails - functions will handle errors gracefully - # Get the ServerEnv instance env = ServerEnv() @@ -69,12 +53,10 @@ def load_hermes_web_cli(): env.validate_service_url = validate_service_url env.generate_session_id = generate_session_id - # Also register the user context helper if needed - return True # Database operations using sqlor-database-module -async def get_all_services(userid: str) -> List[Dict]: +async def get_all_services_old(userid: str) -> List[Dict]: """Get all registered Hermes services for the current user from database.""" try: # Query services table with user_id filter using sqlor-database-module @@ -475,22 +457,6 @@ async def get_session_by_id(userid, session_id: str) -> Optional[Dict]: """ from ahserver.serverenv import ServerEnv - # Initialize database tables if needed - try: - from .init_db import init_database - import asyncio - # Run database initialization in a new event loop if needed - try: - asyncio.get_running_loop() - # If we're already in an async context, create a task - asyncio.create_task(init_database()) - except RuntimeError: - # No running loop, run synchronously - asyncio.run(init_database()) - except Exception as e: - print(f"Warning: Database initialization failed: {str(e)}") - # Continue loading even if DB init fails - functions will handle errors gracefully - # Get the ServerEnv instance env = ServerEnv()