From 469ae0a37817635308d57e7be6650a151c86f941 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 3 Jan 2024 17:43:44 +0530 Subject: [PATCH] fix(proxy/utils.py): don't keep connecting to db if connection already established --- litellm/proxy/proxy_server.py | 2 +- litellm/proxy/utils.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index bdd886fc0..132559c3d 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1014,7 +1014,7 @@ async def startup_event(): ) # start the background health check coroutine. print_verbose(f"prisma client - {prisma_client}") - if prisma_client: + if prisma_client is not None: await prisma_client.connect() if prisma_client is not None and master_key is not None: diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index bb855d9f7..c727c7988 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -255,7 +255,7 @@ class PrismaClient: ) ## init logging object self.proxy_logging_obj = proxy_logging_obj - + self.connected = False os.environ["DATABASE_URL"] = database_url # Save the current working directory original_dir = os.getcwd() @@ -505,7 +505,11 @@ class PrismaClient: ) async def connect(self): try: - await self.db.connect() + if self.connected == False: + await self.db.connect() + self.connected = True + else: + return except Exception as e: asyncio.create_task( self.proxy_logging_obj.failure_handler(original_exception=e)