`get_model_name_from_config` raises `KeyError` instead of returning empty string
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in backend/utils/config_utils.py:41-49 and trace the callers in backend/utils/llm_utils.py:77 and backend/utils/memory_utils.py:47,55. Reproduce the failure with a non-numeric LLM_ID, then verify that empty or partial model configuration dictionaries return an empty or usable model name without raising KeyError.
Written by the indexing model from the issue text.
Description
backend/utils/config_utils.py:41-49:
def get_model_name_from_config(model_config: Dict[str, Any]) -> str:
"""Get model name from model id"""
if model_config is None:
return ""
model_repo = model_config["model_repo"]
model_name = model_config["model_name"]
if not model_repo:
return model_name
return f"{model_repo}/{model_name}"
The function defends against None but not against partial dicts. Two callers — backend/utils/llm_utils.py:77 (OpenAIModel(model_id=get_model_name_from_config(llm_model_config) if llm_model_config else "")) and backend/utils/memory_utils.py:47, 55 — pass dicts that come straight from tenant_config_manager.get_model_config(). That manager returns default={} whenever the model id can't be parsed (config_utils.py:101), which means a sneaky path exists where you get an {} dict rather than None, and accessing model_config["model_repo"] then raises KeyError.
Concrete repro: configure a tenant with a non-numeric LLM_ID. get_model_config returns default which the caller may have passed as {} or as a partial dict like {"model_name": "x"}. The next call into get_model_name_from_config blows up.
Suggested fix
def get_model_name_from_config(model_config: Dict[str, Any]) -> str:
if not model_config:
return ""
model_repo = model_config.get("model_repo") or ""
model_name = model_config.get("model_name") or ""
if not model_repo:
return model_name
return f"{model_repo}/{model_name}"
Severity: Medium. The crash propagates up and the user sees a 500.
- Dominant language
- Python
- Stars
- 5.9k
- Forks
- 731
- Avg merge
- 16h 45m
- Merged PRs (30d)
- 181
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ModelEngine-Group/nexent
-
OpenAIModel: default observer is the class, not an instance — TypeError on any call that omits it Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
ModelEngine-Group/nexent#3921 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ModelEngine-Group/nexent#3818 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ModelEngine-Group/nexent#3817 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
ModelEngine-Group/nexent#3813 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ModelEngine-Group/nexent#3811 ·
All issues in ModelEngine-Group/nexent
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100