From 48ea043f82414e4296a46a3ae1c8daaa8939d1c6 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Thu, 28 May 2026 17:23:25 -0400 Subject: [PATCH] fix(prompts): resolve undefined session variable in _get_access_grants and _to_prompt_model (#25129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both _get_access_grants and _to_prompt_model referenced an undefined local variable 'session' instead of the 'db' parameter passed to each method. Because these helpers are called outside of any 'async with get_async_db_context()' block, 'session' did not exist in their scope, causing a NameError on every prompt fetch. The NameError was silently swallowed by the broad 'except Exception' clause in get_prompt_by_id, which returned None — causing the frontend [id]/+page.svelte to immediately redirect back to /workspace/prompts rather than rendering the prompt editor. Also adds the missing 'logging' import and module-level 'log' logger, which was referenced (but never imported) in insert_new_prompt, update_prompt_version, and delete_prompt_by_id. --- backend/open_webui/models/prompts.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/models/prompts.py b/backend/open_webui/models/prompts.py index ac0d386743..54deeda3d4 100644 --- a/backend/open_webui/models/prompts.py +++ b/backend/open_webui/models/prompts.py @@ -3,10 +3,13 @@ from __future__ import annotations import json +import logging import time import uuid from typing import Optional +log = logging.getLogger(__name__) + from open_webui.internal.db import Base, JSONField, get_async_db_context from open_webui.models.access_grants import AccessGrantModel, AccessGrants from open_webui.models.groups import Groups @@ -90,7 +93,7 @@ class PromptForm(BaseModel): class PromptsTable: async def _get_access_grants(self, prompt_id: str, db: AsyncSession | None = None) -> list[AccessGrantModel]: - return await AccessGrants.get_grants_by_resource('prompt', prompt_id, db=session) + return await AccessGrants.get_grants_by_resource('prompt', prompt_id, db=db) async def _to_prompt_model( self, @@ -100,7 +103,7 @@ class PromptsTable: ) -> PromptModel: prompt_data = PromptModel.model_validate(prompt).model_dump(exclude={'access_grants'}) prompt_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(prompt_data['id'], db=session) + access_grants if access_grants is not None else await self._get_access_grants(prompt_data['id'], db=db) ) return PromptModel.model_validate(prompt_data)