Preserve UISettings docstring on effective class for GET schema

create_model does not inherit the base class docstring, so once an
extension registered a field the effective class had no description.
The UI renders schema.description as a header paragraph — losing it
broke the 'Configuration for UI-specific flags' text. Pass __doc__
through explicitly and add a regression test.
This commit is contained in:
Yuneng Jiang
2026-04-24 13:56:59 -07:00
parent 85b6cae508
commit b300dc3e54
2 changed files with 50 additions and 0 deletions
@@ -235,6 +235,7 @@ def _get_effective_ui_settings_class() -> Type[UISettings]:
_EFFECTIVE_UI_SETTINGS_CLASS = create_model( # type: ignore[call-overload]
"EffectiveUISettings",
__base__=UISettings,
__doc__=UISettings.__doc__,
**_EXTRA_UI_SETTINGS_FIELDS,
)
return _EFFECTIVE_UI_SETTINGS_CLASS
@@ -888,6 +888,55 @@ class TestProxySettingEndpoints:
where={"id": "ui_settings"}
)
def test_get_ui_settings_schema_description_preserved_with_extensions(
self, mock_auth, monkeypatch
):
"""The UI renders ``schema.description`` as a header paragraph.
When an extension package registers extra fields, the effective
class is built via ``create_model`` — which drops the base
class docstring unless we pass ``__doc__`` explicitly."""
from unittest.mock import AsyncMock, MagicMock
from pydantic.fields import FieldInfo
from litellm.proxy.ui_crud_endpoints import proxy_setting_endpoints
from litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints import (
_EXTRA_UI_SETTINGS_FIELDS,
ALLOWED_UI_SETTINGS_FIELDS,
register_extra_ui_setting,
)
# Snapshot + restore extension registry so the test doesn't leak.
original_fields = dict(_EXTRA_UI_SETTINGS_FIELDS)
original_allowed = set(ALLOWED_UI_SETTINGS_FIELDS)
monkeypatch.setattr(
proxy_setting_endpoints, "_EFFECTIVE_UI_SETTINGS_CLASS", None
)
try:
register_extra_ui_setting(
"test_extension_flag", bool, FieldInfo(default=False)
)
mock_prisma = MagicMock()
mock_prisma.db.litellm_uisettings.find_unique = AsyncMock(return_value=None)
monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma)
response = client.get("/get/ui_settings")
assert response.status_code == 200
data = response.json()
assert (
data["field_schema"]["description"]
== "Configuration for UI-specific flags"
)
finally:
_EXTRA_UI_SETTINGS_FIELDS.clear()
_EXTRA_UI_SETTINGS_FIELDS.update(original_fields)
ALLOWED_UI_SETTINGS_FIELDS.clear()
ALLOWED_UI_SETTINGS_FIELDS.update(original_allowed)
proxy_setting_endpoints._EFFECTIVE_UI_SETTINGS_CLASS = None
@pytest.mark.parametrize(
"user_role",
[