@@ -250,30 +250,36 @@ def on_backoff(details):
250
250
251
251
class PrismaClient :
252
252
def __init__ (self , database_url : str , proxy_logging_obj : ProxyLogging ):
253
- print_verbose (
254
- "LiteLLM: DATABASE_URL Set in config, trying to 'pip install prisma'"
255
- )
256
- ## init logging object
257
- self .proxy_logging_obj = proxy_logging_obj
258
- os .environ ["DATABASE_URL" ] = database_url
259
- # Save the current working directory
260
- original_dir = os .getcwd ()
261
- # set the working directory to where this script is
262
- abspath = os .path .abspath (__file__ )
263
- dname = os .path .dirname (abspath )
264
- os .chdir (dname )
265
-
253
+ ### Check if prisma client can be imported (setup done in Docker build)
266
254
try :
267
- subprocess .run (["prisma" , "generate" ])
268
- subprocess .run (
269
- ["prisma" , "db" , "push" , "--accept-data-loss" ]
270
- ) # this looks like a weird edge case when prisma just wont start on render. we need to have the --accept-data-loss
271
- finally :
272
- os .chdir (original_dir )
273
- # Now you can import the Prisma Client
274
- from prisma import Client # type: ignore
275
-
276
- self .db = Client () # Client to connect to Prisma db
255
+ from prisma import Client # type: ignore
256
+
257
+ self .db = Client () # Client to connect to Prisma db
258
+ except : # if not - go through normal setup process
259
+ print_verbose (
260
+ "LiteLLM: DATABASE_URL Set in config, trying to 'pip install prisma'"
261
+ )
262
+ ## init logging object
263
+ self .proxy_logging_obj = proxy_logging_obj
264
+ os .environ ["DATABASE_URL" ] = database_url
265
+ # Save the current working directory
266
+ original_dir = os .getcwd ()
267
+ # set the working directory to where this script is
268
+ abspath = os .path .abspath (__file__ )
269
+ dname = os .path .dirname (abspath )
270
+ os .chdir (dname )
271
+
272
+ try :
273
+ subprocess .run (["prisma" , "generate" ])
274
+ subprocess .run (
275
+ ["prisma" , "db" , "push" , "--accept-data-loss" ]
276
+ ) # this looks like a weird edge case when prisma just wont start on render. we need to have the --accept-data-loss
277
+ finally :
278
+ os .chdir (original_dir )
279
+ # Now you can import the Prisma Client
280
+ from prisma import Client # type: ignore
281
+
282
+ self .db = Client () # Client to connect to Prisma db
277
283
278
284
def hash_token (self , token : str ):
279
285
# Hash the string using SHA-256
0 commit comments