2357582 fix: improve model sorting by handling missing names
📊 Changes
1 file changed (+4 additions, -1 deletions)
View changed files
📝backend/open_webui/main.py (+4 -1)
📄 Description
Target branch: Verified that this pull request targets the dev branch.
Description: Provided a concise description of the changes made in this pull request.
Changelog: Added a changelog entry in Keep a Changelog format at the bottom of this PR description.
Documentation: No documentation changes needed — behavior remains the same for users.
Dependencies: No new dependencies introduced.
Testing: Manually tested to confirm /api/models endpoint no longer fails when a model has no name.
Code review: Performed a self-review for coding standards and project style.
Prefix:fix: Prevent /api/models from failing when models have missing names
Changelog Entry
Description
Fixes a bug in /api/models where the server returned a 500 error if any model in the list was missing a name field (or had it set to null).
Implemented a safe sort key that falls back to an empty string for missing names, preventing TypeError comparisons between None and str.
Added
None
Changed
Updated sort key in get_models() to use .get() with a fallback when sorting by model name.
Deprecated
None
Removed
None
Fixed
Fix: Resolved TypeError: '<' not supported between instances of 'NoneType' and 'str' when sorting models in /api/models.
Security
No security changes.
Breaking Changes
None
Additional Information
This bug surfaced when a configured provider (e.g., OpenAI, Ollama) returned model entries with a missing or null name field.
Instead of failing the entire endpoint, the fix ensures such entries are still included and safely sorted.
Related logs:
TypeError: '<' not supported between instances of 'NoneType' and 'str'
Screenshots or Videos
Not applicable – API behavior fix.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/16547
**Author:** [@Gyarbij](https://github.com/Gyarbij)
**Created:** 8/12/2025
**Status:** ✅ Merged
**Merged:** 8/13/2025
**Merged by:** [@tjbck](https://github.com/tjbck)
**Base:** `dev` ← **Head:** `main`
---
### 📝 Commits (1)
- [`2357582`](https://github.com/open-webui/open-webui/commit/23575825a18d8d1e5fa1fe1f400c9ab168525e0f) fix: improve model sorting by handling missing names
### 📊 Changes
**1 file changed** (+4 additions, -1 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/main.py` (+4 -1)
</details>
### 📄 Description
* [x] **Target branch:** Verified that this pull request targets the `dev` branch.
* [x] **Description:** Provided a concise description of the changes made in this pull request.
* [x] **Changelog:** Added a changelog entry in Keep a Changelog format at the bottom of this PR description.
* [ ] **Documentation:** No documentation changes needed — behavior remains the same for users.
* [x] **Dependencies:** No new dependencies introduced.
* [x] **Testing:** Manually tested to confirm `/api/models` endpoint no longer fails when a model has no `name`.
* [x] **Code review:** Performed a self-review for coding standards and project style.
* [x] **Prefix:** `fix: Prevent /api/models from failing when models have missing names`
---
# Changelog Entry
### Description
* Fixes a bug in `/api/models` where the server returned a 500 error if any model in the list was missing a `name` field (or had it set to `null`).
* Implemented a safe sort key that falls back to an empty string for missing names, preventing `TypeError` comparisons between `None` and `str`.
### Added
* None
### Changed
* Updated sort key in `get_models()` to use `.get()` with a fallback when sorting by model name.
### Deprecated
* None
### Removed
* None
### Fixed
* **Fix:** Resolved `TypeError: '<' not supported between instances of 'NoneType' and 'str'` when sorting models in `/api/models`.
### Security
* No security changes.
### Breaking Changes
* None
---
### Additional Information
* This bug surfaced when a configured provider (e.g., OpenAI, Ollama) returned model entries with a missing or null `name` field.
* Instead of failing the entire endpoint, the fix ensures such entries are still included and safely sorted.
* Related logs:
```
TypeError: '<' not supported between instances of 'NoneType' and 'str'
```
### Screenshots or Videos
*Not applicable – API behavior fix.*
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/16547
Author: @Gyarbij
Created: 8/12/2025
Status: ✅ Merged
Merged: 8/13/2025
Merged by: @tjbck
Base:
dev← Head:main📝 Commits (1)
2357582fix: improve model sorting by handling missing names📊 Changes
1 file changed (+4 additions, -1 deletions)
View changed files
📝
backend/open_webui/main.py(+4 -1)📄 Description
devbranch./api/modelsendpoint no longer fails when a model has noname.fix: Prevent /api/models from failing when models have missing namesChangelog Entry
Description
/api/modelswhere the server returned a 500 error if any model in the list was missing anamefield (or had it set tonull).TypeErrorcomparisons betweenNoneandstr.Added
Changed
get_models()to use.get()with a fallback when sorting by model name.Deprecated
Removed
Fixed
TypeError: '<' not supported between instances of 'NoneType' and 'str'when sorting models in/api/models.Security
Breaking Changes
Additional Information
This bug surfaced when a configured provider (e.g., OpenAI, Ollama) returned model entries with a missing or null
namefield.Instead of failing the entire endpoint, the fix ensures such entries are still included and safely sorted.
Related logs:
Screenshots or Videos
Not applicable – API behavior fix.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.