diff --git a/backend/open_webui/models/calendar.py b/backend/open_webui/models/calendar.py index 4faad1a456..efdfd291ba 100644 --- a/backend/open_webui/models/calendar.py +++ b/backend/open_webui/models/calendar.py @@ -241,11 +241,11 @@ class CalendarTable: access_grants: Optional[list[AccessGrantModel]] = None, db: Optional[AsyncSession] = None, ) -> CalendarModel: - cal_data = CalendarModel.model_validate(cal).model_dump(exclude={'access_grants'}) - cal_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(cal_data['id'], db=db) + calendar_model = CalendarModel.model_validate(cal) + calendar_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(calendar_model.id, db=db) ) - return CalendarModel.model_validate(cal_data) + return calendar_model async def get_or_create_defaults(self, user_id: str, db: Optional[AsyncSession] = None) -> list[CalendarModel]: """Return user's calendars, creating 'Personal' default if none exist.""" diff --git a/backend/open_webui/models/channels.py b/backend/open_webui/models/channels.py index 5028cdf2c8..95cc58cd32 100644 --- a/backend/open_webui/models/channels.py +++ b/backend/open_webui/models/channels.py @@ -266,11 +266,11 @@ class ChannelTable: access_grants: Optional[list[AccessGrantModel]] = None, db: Optional[AsyncSession] = None, ) -> ChannelModel: - channel_data = ChannelModel.model_validate(channel).model_dump(exclude={'access_grants'}) - channel_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(channel_data['id'], db=db) + channel_model = ChannelModel.model_validate(channel) + channel_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(channel_model.id, db=db) ) - return ChannelModel.model_validate(channel_data) + return channel_model async def _collect_unique_user_ids( self, diff --git a/backend/open_webui/models/knowledge.py b/backend/open_webui/models/knowledge.py index dceb3cbec0..52a78c46c1 100644 --- a/backend/open_webui/models/knowledge.py +++ b/backend/open_webui/models/knowledge.py @@ -195,11 +195,11 @@ class KnowledgeTable: access_grants: Optional[list[AccessGrantModel]] = None, db: Optional[AsyncSession] = None, ) -> KnowledgeModel: - knowledge_data = KnowledgeModel.model_validate(knowledge).model_dump(exclude={'access_grants'}) - knowledge_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(knowledge_data['id'], db=db) + knowledge_model = KnowledgeModel.model_validate(knowledge) + knowledge_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(knowledge_model.id, db=db) ) - return KnowledgeModel.model_validate(knowledge_data) + return knowledge_model async def insert_new_knowledge( self, user_id: str, form_data: KnowledgeForm, db: Optional[AsyncSession] = None diff --git a/backend/open_webui/models/models.py b/backend/open_webui/models/models.py index 5f44d59405..95300c7dd2 100755 --- a/backend/open_webui/models/models.py +++ b/backend/open_webui/models/models.py @@ -199,11 +199,11 @@ class ModelsTable: if db is not None: await db.commit() - model_data = ModelModel.model_validate(model).model_dump(exclude={'access_grants'}) - model_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(model_data['id'], db=db) + model_model = ModelModel.model_validate(model) + model_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(model_model.id, db=db) ) - return ModelModel.model_validate(model_data) + return model_model async def insert_new_model( self, form_data: ModelForm, user_id: str, db: AsyncSession | None = None diff --git a/backend/open_webui/models/notes.py b/backend/open_webui/models/notes.py index 01986d9cfe..8d8eb2414f 100644 --- a/backend/open_webui/models/notes.py +++ b/backend/open_webui/models/notes.py @@ -106,12 +106,12 @@ class NoteTable: db: Optional[AsyncSession] = None, ) -> NoteModel: # We exclude access_grants to inject them - note_data = NoteModel.model_validate(note).model_dump(exclude={'access_grants'}) - note_data['data'] = note_data.get('data') or {} - note_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(note_data['id'], db=db) + note_model = NoteModel.model_validate(note) + note_model.data = note_model.data or {} + note_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(note_model.id, db=db) ) - return NoteModel.model_validate(note_data) + return note_model def _has_permission(self, db, query, filter: dict, permission: str = 'read'): return AccessGrants.has_permission_filter( diff --git a/backend/open_webui/models/prompts.py b/backend/open_webui/models/prompts.py index 61ce0fc218..f4f4187f17 100644 --- a/backend/open_webui/models/prompts.py +++ b/backend/open_webui/models/prompts.py @@ -103,11 +103,11 @@ class PromptsTable: access_grants: list[AccessGrantModel | None] = None, db: AsyncSession | None = None, ) -> 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=db) + prompt_model = PromptModel.model_validate(prompt) + prompt_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(prompt_model.id, db=db) ) - return PromptModel.model_validate(prompt_data) + return prompt_model async def insert_new_prompt( self, user_id: str, form_data: PromptForm, db: AsyncSession | None = None diff --git a/backend/open_webui/models/skills.py b/backend/open_webui/models/skills.py index c3c007cdd9..b4a64fd02d 100644 --- a/backend/open_webui/models/skills.py +++ b/backend/open_webui/models/skills.py @@ -113,11 +113,11 @@ class SkillsTable: access_grants: Optional[list[AccessGrantModel]] = None, db: Optional[AsyncSession] = None, ) -> SkillModel: - skill_data = SkillModel.model_validate(skill).model_dump(exclude={'access_grants'}) - skill_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(skill_data['id'], db=db) + skill_model = SkillModel.model_validate(skill) + skill_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(skill_model.id, db=db) ) - return SkillModel.model_validate(skill_data) + return skill_model async def insert_new_skill( self, diff --git a/backend/open_webui/models/tools.py b/backend/open_webui/models/tools.py index 86568288e0..cbc21854ea 100644 --- a/backend/open_webui/models/tools.py +++ b/backend/open_webui/models/tools.py @@ -106,11 +106,11 @@ class ToolsTable: access_grants: list[AccessGrantModel | None] = None, db: AsyncSession | None = None, ) -> ToolModel: - tool_data = ToolModel.model_validate(tool).model_dump(exclude={'access_grants'}) - tool_data['access_grants'] = ( - access_grants if access_grants is not None else await self._get_access_grants(tool_data['id'], db=db) + tool_model = ToolModel.model_validate(tool) + tool_model.access_grants = ( + access_grants if access_grants is not None else await self._get_access_grants(tool_model.id, db=db) ) - return ToolModel.model_validate(tool_data) + return tool_model async def insert_new_tool( self,