fix: gracefully handle missing functions when loading models (#21476)

When models reference functions (via filterIds/actionIds) that no longer
exist in the database, the /api/models endpoint crashes with a 500 error,
preventing the UI from loading chats entirely. This can happen after
upgrades when built-in functions are removed or when user-created
functions are deleted while still referenced by models.

Instead of raising an exception, log at INFO level and skip the missing
function so the rest of the models load successfully.

Fixes #21464

https://claude.ai/code/session_015JRM7m2bNeZPBBmV2Gv4Mj

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Classic298
2026-02-16 20:02:54 +01:00
committed by GitHub
parent 0b2abe6cb8
commit 656de56a3e

View File

@@ -320,9 +320,13 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
for action_id in action_ids:
action_function = functions_by_id.get(action_id)
if action_function is None:
raise Exception(f"Action not found: {action_id}")
log.info(f"Action not found: {action_id}")
continue
function_module = request.app.state.FUNCTIONS.get(action_id)
if function_module is None:
log.info(f"Failed to load action module: {action_id}")
continue
model["actions"].extend(
get_action_items_from_module(action_function, function_module)
)
@@ -331,10 +335,13 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
for filter_id in filter_ids:
filter_function = functions_by_id.get(filter_id)
if filter_function is None:
raise Exception(f"Filter not found: {filter_id}")
log.info(f"Filter not found: {filter_id}")
continue
function_module = request.app.state.FUNCTIONS.get(filter_id)
if function_module is None:
log.info(f"Failed to load filter module: {filter_id}")
continue
if getattr(function_module, "toggle", None):
model["filters"].extend(
get_filter_items_from_module(filter_function, function_module)