Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(lightrag): reject legacy model fields on fresh settings

NoxsMedia2073493a467f
diff --git a/deeptutor/api/routers/knowledge.py b/deeptutor/api/routers/knowledge.py
index 11bd553b7..8947b2502 100644
--- a/deeptutor/api/routers/knowledge.py
+++ b/deeptutor/api/routers/knowledge.py
@@ -1601,6 +1601,11 @@ async def update_lightrag_pipeline_config(payload: LightRagConfigUpdate):
candidate = {**current, **updates}
if "role_models" in payload.model_fields_set and payload.role_models is None:
raise HTTPException(status_code=422, detail="Role models cannot be cleared.")
+ if (
+ current.get("version") == 2
+ and {"llm_profile_id", "llm_model_id"} & payload.model_fields_set
+ ):
+ raise HTTPException(status_code=422, detail="Use role_models for this configuration.")
if candidate.get("role_models") is not None:
from deeptutor.services.rag.pipelines.lightrag.roles import validate_models
diff --git a/tests/api/test_knowledge_router.py b/tests/api/test_knowledge_router.py
index 34f2ac6ad..890681a53 100644
--- a/tests/api/test_knowledge_router.py
+++ b/tests/api/test_knowledge_router.py
@@ -2730,6 +2730,7 @@ def test_lightrag_config_validates_dedicated_llm_selection(monkeypatch, tmp_path
from deeptutor.services.config.model_catalog import ModelCatalogService
settings_service = RuntimeSettingsService(tmp_path, process_env={})
+ settings_service.save_lightrag({"version": 1})
catalog_service = ModelCatalogService(tmp_path / "model_catalog.json")
catalog_service.save(
{
@@ -2809,6 +2810,12 @@ def test_lightrag_role_settings_validate_before_save(monkeypatch, tmp_path):
monkeypatch.setattr(roles, "validate_models", validate)
client = TestClient(_build_app())
url = "/api/knowledge-bases/rag-pipelines/lightrag/config"
+ fresh = client.get(url).json()
+ assert fresh["version"] == 2
+ assert (
+ client.put(url, json={"llm_profile_id": "public", "llm_model_id": "ok"}).status_code == 422
+ )
+ assert client.get(url).json() == fresh
models = {
"base": {"profile_id": "public", "model_id": "ok"},
"query": {"mode": "inherit", "reasoning_effort": "adaptive"},