From 8fe2a7bb75e222f49f177437a0e1b5279b23a37e Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 3 Jul 2024 23:39:16 -0700 Subject: [PATCH] fix --- backend/apps/webui/internal/db.py | 8 +++++++- backend/apps/webui/models/tools.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/apps/webui/internal/db.py b/backend/apps/webui/internal/db.py index bfdc52c11..333e215ea 100644 --- a/backend/apps/webui/internal/db.py +++ b/backend/apps/webui/internal/db.py @@ -62,10 +62,16 @@ Base = declarative_base() Session = scoped_session(SessionLocal) +from contextlib import contextmanager + + # Dependency -def get_db(): +def get_session(): db = SessionLocal() try: yield db finally: db.close() + + +get_db = contextmanager(get_session) diff --git a/backend/apps/webui/models/tools.py b/backend/apps/webui/models/tools.py index dc0fe01c5..4cc06826a 100644 --- a/backend/apps/webui/models/tools.py +++ b/backend/apps/webui/models/tools.py @@ -119,7 +119,8 @@ class ToolsTable: return None 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]: try: