fix(internal_user_endpoints.py): re-introduce upsert on user not found

Fixes https://github.com/BerriAI/litellm/issues/9243
This commit is contained in:
Krrish Dholakia 2025-03-19 19:28:11 -07:00
parent 220aa66f98
commit 07b1e6aa1c
2 changed files with 9 additions and 7 deletions

View file

@ -737,13 +737,16 @@ async def user_update(
existing_user_row = await prisma_client.db.litellm_usertable.find_first(
where={"user_id": data.user_id}
)
if existing_user_row is None:
raise Exception(f"User not found, passed user_id={data.user_id}")
existing_user_row = LiteLLM_UserTable(
**existing_user_row.model_dump(exclude_none=True)
)
if existing_user_row is not None:
existing_user_row = LiteLLM_UserTable(
**existing_user_row.model_dump(exclude_none=True)
)
existing_metadata = cast(Dict, getattr(existing_user_row, "metadata", {}) or {})
existing_metadata = (
cast(Dict, getattr(existing_user_row, "metadata", {}) or {})
if existing_user_row is not None
else {}
)
non_default_values = prepare_metadata_fields(
data=data,