From 48f78ca58d1eaeb492f3385c90b8d2511f42a32f Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Fri, 24 Jul 2026 07:00:37 +0200 Subject: [PATCH] fix: prevent startup crash when function/tool has null user_id (#26850) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Function and Tool database columns declare user_id as a nullable String column, but their Pydantic read-models required a non-null string. A record with user_id NULL therefore raised a pydantic ValidationError inside get_functions()/get_tools(), which run during install_tool_and_function_dependencies() at app startup — crashing the whole application and blocking all chat completions. Make user_id Optional in the read/response models so such records validate gracefully (user is already rendered as None downstream when the id has no matching user) instead of taking down startup. Claude-Session: https://claude.ai/code/session_01Y4RRUNq7ZUFkRWbWPkDw3m Co-authored-by: Claude --- backend/open_webui/models/functions.py | 6 +++--- backend/open_webui/models/tools.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/models/functions.py b/backend/open_webui/models/functions.py index 3747d9e09a..573880d521 100644 --- a/backend/open_webui/models/functions.py +++ b/backend/open_webui/models/functions.py @@ -42,7 +42,7 @@ class FunctionMeta(BaseModel): class FunctionModel(BaseModel): id: str - user_id: str + user_id: str | None = None # may be null for legacy/malformed records name: str type: str content: str @@ -58,7 +58,7 @@ class FunctionModel(BaseModel): # --- form / schema definitions --- class FunctionWithValvesModel(BaseModel): id: str - user_id: str + user_id: str | None = None # may be null for legacy/malformed records name: str type: str content: str @@ -79,7 +79,7 @@ class FunctionWithValvesModel(BaseModel): class FunctionResponse(BaseModel): id: str - user_id: str + user_id: str | None = None # may be null for legacy/malformed records type: str name: str meta: FunctionMeta diff --git a/backend/open_webui/models/tools.py b/backend/open_webui/models/tools.py index d4bcf1f631..86568288e0 100644 --- a/backend/open_webui/models/tools.py +++ b/backend/open_webui/models/tools.py @@ -41,7 +41,7 @@ class ToolMeta(BaseModel): class ToolModel(BaseModel): id: str - user_id: str + user_id: str | None = None # may be null for legacy/malformed records name: str # None when listed with defer_content=True (source skipped for listings) content: str | None = None @@ -66,7 +66,7 @@ class ToolUserModel(ToolModel): class ToolResponse(BaseModel): id: str - user_id: str + user_id: str | None = None # may be null for legacy/malformed records name: str meta: ToolMeta access_grants: list[AccessGrantModel] = Field(default_factory=list)