fix(customer): resolve budget_id field routing and missing required fields in /customer/update

- Fix incorrect Prisma relation field from "litellm_endusertable" to "end_users"
- Route budget_id to end user data instead of budget table data for linking existing budgets
- Add required created_by and updated_by fields when creating new budgets
- Import missing litellm_proxy_admin_name dependency

Fixes #12437 - 500 error when updating customer with budget_id
This commit is contained in:
Jason Jensen 2025-07-08 23:01:32 +00:00
parent df2a2fac43
commit 956ed08003

View file

@ -417,7 +417,7 @@ async def update_end_user(
```
"""
from litellm.proxy.proxy_server import prisma_client
from litellm.proxy.proxy_server import litellm_proxy_admin_name, prisma_client
try:
data_json: dict = data.json()
@ -459,19 +459,29 @@ async def update_end_user(
budget_table_data = {}
update_end_user_table_data = {}
for k, v in non_default_values.items():
if k in LiteLLM_BudgetTable.model_fields.keys():
# budget_id is for linking to existing budget, not for creating new budget
if k == "budget_id":
update_end_user_table_data[k] = v
elif k in LiteLLM_BudgetTable.model_fields.keys():
budget_table_data[k] = v
if k in LiteLLM_EndUserTable.model_fields.keys():
elif k in LiteLLM_EndUserTable.model_fields.keys():
update_end_user_table_data[k] = v
## Check if budget id is set ##
## Check if we need to create a new budget (only if budget fields are provided, not just budget_id) ##
if budget_table_data:
if end_user_budget_table is None:
## Create new budget ##
budget_table_data_record = (
await prisma_client.db.litellm_budgettable.create(
data=budget_table_data, include={"litellm_endusertable": True}
data={
**budget_table_data,
"created_by": user_api_key_dict.user_id
or litellm_proxy_admin_name,
"updated_by": user_api_key_dict.user_id
or litellm_proxy_admin_name,
},
include={"end_users": True},
)
)