Skip to content

Commit 31111a6

Browse files
committed
fix: guard null parentId on user message save
1 parent 1e9eac4 commit 31111a6

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

backend/open_webui/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,13 @@ async def chat_completion(
18911891
# Save user message to DB
18921892
user_message = metadata.get('user_message') or {}
18931893
if user_message and user_message.get('id'):
1894+
# Guard: infer parentId from chat's currentId when frontend sends null
1895+
if not user_message.get('parentId'):
1896+
_existing = locals().get('existing_chat') or await Chats.get_chat_by_id(chat_id)
1897+
_current_id = (_existing.chat or {}).get('history', {}).get('currentId') if _existing else None
1898+
if _current_id and _current_id != user_message['id']:
1899+
user_message['parentId'] = _current_id
1900+
18941901
await Chats.upsert_message_to_chat_by_id_and_message_id(
18951902
chat_id,
18961903
user_message['id'],

0 commit comments

Comments
 (0)