update the chat state version with messages

This commit is contained in:
CREDO23 2025-10-24 01:34:26 +02:00 committed by thierryverse
parent 13342eb823
commit cc3e04031e
2 changed files with 44 additions and 27 deletions

View file

@ -259,9 +259,10 @@ async def update_chat(
db_chat = await read_chat(chat_id, session, user)
update_data = chat_update.model_dump(exclude_unset=True)
for key, value in update_data.items():
if key == "messages":
db_chat.state_version = len(update_data["messages"])
setattr(db_chat, key, value)
# Increment state_version when chat is modified
db_chat.state_version = (db_chat.state_version or 0) + 1
await session.commit()
await session.refresh(db_chat)
return db_chat