fix(proxy/models): resolve basedpyright type issues in model validators

This commit is contained in:
Prince Thummar 2026-09-01 18:50:08 +05:30
parent a6f0faa5b1
commit bc9e85dedb
3 changed files with 28 additions and 37 deletions

View file

@ -5,7 +5,7 @@ Canonical definition for ``litellm_endusertable``. Re-exported from
``litellm.proxy._types`` for backwards compatibility.
"""
from typing import Final, Literal
from typing import Literal
from pydantic import BaseModel, ConfigDict, model_validator
@ -28,18 +28,16 @@ class LiteLLM_EndUserTable(LiteLLMPydanticObjectBase):
@model_validator(mode="before")
@classmethod
def set_model_info(cls, values: object) -> object:
def set_model_info(cls, values):
if isinstance(values, BaseModel):
raw: Final = values.model_dump() # mutable-ok: pydantic before-validator dict payload
raw = values.model_dump() # rebind-ok: normalize model input
elif hasattr(values, "__dict__") and not isinstance(values, dict):
raw: Final = dict(values.__dict__) # mutable-ok: object normalization for ORM/Prisma models
raw = dict(values.__dict__) # rebind-ok: normalize object input # mutable-ok: object normalization
else:
raw: Final = values
raw = values # rebind-ok: preserve input
if isinstance(raw, dict):
if raw.get("spend") is None:
return {**raw, "spend": 0.0} # mutable-ok: default spend for uninitialized rows
return raw
return values
if isinstance(raw, dict) and raw.get("spend") is None:
raw.update({"spend": 0.0}) # mutable-ok: default spend value
return raw
model_config = ConfigDict(protected_namespaces=())

View file

@ -6,7 +6,6 @@ Canonical definition for ``litellm_tagtable``. Re-exported from
"""
from datetime import datetime
from typing import Final
from pydantic import BaseModel, model_validator
@ -28,20 +27,17 @@ class LiteLLM_TagTable(LiteLLMPydanticObjectBase):
@model_validator(mode="before")
@classmethod
def set_model_info(cls, values: object) -> object:
def set_model_info(cls, values):
if isinstance(values, BaseModel):
raw: Final = values.model_dump() # mutable-ok: pydantic before-validator dict payload
raw = values.model_dump() # rebind-ok: normalize model input
elif hasattr(values, "__dict__") and not isinstance(values, dict):
raw: Final = dict(values.__dict__) # mutable-ok: object normalization for ORM/Prisma models
raw = dict(values.__dict__) # rebind-ok: normalize object input # mutable-ok: object normalization
else:
raw: Final = values
raw = values # rebind-ok: preserve input
if isinstance(raw, dict):
updates: Final = { # mutable-ok: default values for uninitialized fields
**({"spend": 0.0} if raw.get("spend") is None else {}), # mutable-ok: conditional default
**({"models": []} if raw.get("models") is None else {}), # mutable-ok: conditional default
}
if updates:
return {**raw, **updates} # mutable-ok: merged normalized model dictionary
return raw
return values
if raw.get("spend") is None:
raw.update({"spend": 0.0}) # mutable-ok: default spend value
if raw.get("models") is None:
raw.update({"models": []}) # mutable-ok: default models value
return raw

View file

@ -6,7 +6,6 @@ Canonical definition for ``litellm_usertable``. Re-exported from
"""
from datetime import datetime
from typing import Final
from pydantic import BaseModel, ConfigDict, Field, model_validator
@ -50,24 +49,22 @@ class LiteLLM_UserTable(LiteLLMPydanticObjectBase):
@model_validator(mode="before")
@classmethod
def set_model_info(cls, values: object) -> object:
def set_model_info(cls, values):
if isinstance(values, BaseModel):
raw: Final = values.model_dump() # mutable-ok: pydantic before-validator dict payload
raw = values.model_dump() # rebind-ok: normalize model input
elif hasattr(values, "__dict__") and not isinstance(values, dict):
raw: Final = dict(values.__dict__) # mutable-ok: object normalization for ORM/Prisma models
raw = dict(values.__dict__) # rebind-ok: normalize object input # mutable-ok: object normalization
else:
raw: Final = values
raw = values # rebind-ok: preserve input
if isinstance(raw, dict):
updates: Final = { # mutable-ok: default values for uninitialized fields
**({"spend": 0.0} if raw.get("spend") is None else {}), # mutable-ok: conditional default
**({"models": []} if raw.get("models") is None else {}), # mutable-ok: conditional default
**({"teams": []} if raw.get("teams") is None else {}), # mutable-ok: conditional default
}
if updates:
return {**raw, **updates} # mutable-ok: merged normalized model dictionary
return raw
return values
if raw.get("spend") is None:
raw.update({"spend": 0.0}) # mutable-ok: default spend value
if raw.get("models") is None:
raw.update({"models": []}) # mutable-ok: default models value
if raw.get("teams") is None:
raw.update({"teams": []}) # mutable-ok: default teams value
return raw
def is_over_budget(self) -> bool:
if self.max_budget is None: