Timothy J. Baek 10 miesięcy temu
rodzic
commit
8fe2a7bb75

+ 7 - 1
backend/apps/webui/internal/db.py

@@ -62,10 +62,16 @@ Base = declarative_base()
 Session = scoped_session(SessionLocal)
 Session = scoped_session(SessionLocal)
 
 
 
 
+from contextlib import contextmanager
+
+
 # Dependency
 # Dependency
-def get_db():
+def get_session():
     db = SessionLocal()
     db = SessionLocal()
     try:
     try:
         yield db
         yield db
     finally:
     finally:
         db.close()
         db.close()
+
+
+get_db = contextmanager(get_session)

+ 2 - 1
backend/apps/webui/models/tools.py

@@ -119,7 +119,8 @@ class ToolsTable:
             return None
             return None
 
 
     def get_tools(self) -> List[ToolModel]:
     def get_tools(self) -> List[ToolModel]:
-        return [ToolModel.model_validate(tool) for tool in db.query(Tool).all()]
+        with get_db() as db:
+            return [ToolModel.model_validate(tool) for tool in db.query(Tool).all()]
 
 
     def get_tool_valves_by_id(self, id: str) -> Optional[dict]:
     def get_tool_valves_by_id(self, id: str) -> Optional[dict]:
         try:
         try: