From bdef1001ac0ff4003dc7e1fdfce4ccf4b16a80ab Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 12 Apr 2025 15:10:43 -0700 Subject: [PATCH] refac --- backend/open_webui/models/memories.py | 5 +++-- backend/open_webui/routers/memories.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/models/memories.py b/backend/open_webui/models/memories.py index c8dae9726..8b10a77cf 100644 --- a/backend/open_webui/models/memories.py +++ b/backend/open_webui/models/memories.py @@ -63,14 +63,15 @@ class MemoriesTable: else: return None - def update_memory_by_id( + def update_memory_by_id_and_user_id( self, id: str, + user_id: str, content: str, ) -> Optional[MemoryModel]: with get_db() as db: try: - db.query(Memory).filter_by(id=id).update( + db.query(Memory).filter_by(id=id, user_id=user_id).update( {"content": content, "updated_at": int(time.time())} ) db.commit() diff --git a/backend/open_webui/routers/memories.py b/backend/open_webui/routers/memories.py index e660ef852..6d54c9c17 100644 --- a/backend/open_webui/routers/memories.py +++ b/backend/open_webui/routers/memories.py @@ -153,7 +153,9 @@ async def update_memory_by_id( form_data: MemoryUpdateModel, user=Depends(get_verified_user), ): - memory = Memories.update_memory_by_id(memory_id, form_data.content) + memory = Memories.update_memory_by_id_and_user_id( + memory_id, user.id, form_data.content + ) if memory is None: raise HTTPException(status_code=404, detail="Memory not found")