mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(model-info): hydrate created_at/created_by/updated_at from row columns for all users
/v1/model/info and /v2/model/info are admin-scoped: the caller already has access to this metadata. The response schema exposes the fields as optional, and the Admin UI renders model_info.created_at / created_by unconditionally, so free-tier admins saw "Unknown" placeholders even though the data existed in the LiteLLM_ProviderModelTable row. Hydrate the four system-managed metadata fields from row top-level columns unconditionally in get_model_info_with_id. Config-file models have no such row attributes, so nothing changes for them.
This commit is contained in:
parent
490c9f9f3f
commit
53bf2d3ade
2 changed files with 30 additions and 6 deletions
|
|
@ -5769,12 +5769,14 @@ class ProxyConfig:
|
|||
model.model_info["db_model"] = True
|
||||
model.model_info["blocked"] = bool(getattr(model, "blocked", False))
|
||||
|
||||
if premium_user is True:
|
||||
# seeing "created_at", "updated_at", "created_by", "updated_by" is a LiteLLM Enterprise Feature
|
||||
model.model_info["created_at"] = getattr(model, "created_at", None)
|
||||
model.model_info["updated_at"] = getattr(model, "updated_at", None)
|
||||
model.model_info["created_by"] = getattr(model, "created_by", None)
|
||||
model.model_info["updated_by"] = getattr(model, "updated_by", None)
|
||||
# Hydrate system-managed metadata unconditionally: /model/info endpoints
|
||||
# are admin-scoped, so the caller already has access to this data.
|
||||
# Config-file models have no row attributes -> nothing is injected.
|
||||
if isinstance(model.model_info, dict):
|
||||
for field_name in ("created_at", "updated_at", "created_by", "updated_by"):
|
||||
field_value = getattr(model, field_name, None)
|
||||
if field_value is not None:
|
||||
model.model_info[field_name] = field_value
|
||||
|
||||
if model.model_info is not None and isinstance(model.model_info, dict):
|
||||
if "id" not in model.model_info:
|
||||
|
|
|
|||
|
|
@ -1871,6 +1871,28 @@ def test_ProxyConfig_get_model_info_with_id_missing_model_id_raises(monkeypatch)
|
|||
pc.get_model_info_with_id(model=bad)
|
||||
|
||||
|
||||
def test_ProxyConfig_get_model_info_with_id_hydrates_metadata_without_premium(monkeypatch):
|
||||
"""DB-row created_at/created_by/updated_at/updated_by are served to non-premium
|
||||
users: /model/info is admin-scoped, so the caller already has access."""
|
||||
monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", False)
|
||||
from datetime import datetime, timezone
|
||||
|
||||
pc = ProxyConfig()
|
||||
now = datetime.now(timezone.utc)
|
||||
model = SimpleNamespace(
|
||||
model_id="m-2",
|
||||
model_info={"id": "m-2"},
|
||||
blocked=False,
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
created_by="user-1",
|
||||
updated_by="user-1",
|
||||
)
|
||||
out = pc.get_model_info_with_id(model=model, db_model=True)
|
||||
assert str(out.created_at) == str(now)
|
||||
assert out.created_by == "user-1"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# ProxyConfig._delete_deployment
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue