@@ -1358,20 +1358,23 @@ async def update_key_fn(
1358
1358
user_api_key_cache = user_api_key_cache ,
1359
1359
)
1360
1360
1361
- team_obj = await get_team_object (
1362
- team_id = cast (str , data .team_id ),
1363
- prisma_client = prisma_client ,
1364
- user_api_key_cache = user_api_key_cache ,
1365
- check_db_only = True ,
1366
- )
1367
-
1368
- if team_obj is not None :
1369
- await _check_team_key_limits (
1370
- team_table = team_obj ,
1371
- data = data ,
1361
+ # Only check team limits if key has a team_id
1362
+ team_obj : Optional [LiteLLM_TeamTableCachedObj ] = None
1363
+ if data .team_id is not None :
1364
+ team_obj = await get_team_object (
1365
+ team_id = data .team_id ,
1372
1366
prisma_client = prisma_client ,
1367
+ user_api_key_cache = user_api_key_cache ,
1368
+ check_db_only = True ,
1373
1369
)
1374
1370
1371
+ if team_obj is not None :
1372
+ await _check_team_key_limits (
1373
+ team_table = team_obj ,
1374
+ data = data ,
1375
+ prisma_client = prisma_client ,
1376
+ )
1377
+
1375
1378
# if team change - check if this is possible
1376
1379
if is_different_team (data = data , existing_key_row = existing_key_row ):
1377
1380
if llm_router is None :
@@ -1381,6 +1384,14 @@ async def update_key_fn(
1381
1384
"error" : "LLM router not found. Please set it up by passing in a valid config.yaml or adding models via the UI."
1382
1385
},
1383
1386
)
1387
+ # team_obj should be set since is_different_team() returns True only when data.team_id is not None
1388
+ if team_obj is None :
1389
+ raise HTTPException (
1390
+ status_code = 500 ,
1391
+ detail = {
1392
+ "error" : "Team object not found for team change validation"
1393
+ },
1394
+ )
1384
1395
validate_key_team_change (
1385
1396
key = existing_key_row ,
1386
1397
team = team_obj ,
0 commit comments